标签:calendar reg cond 星期几 方法 system ring project add
package DateProject; /** * 测试日历类 * 一月份为0,二月份为1 * 周日为1,周一为2 * @author 4090039qrh * */ import java.util.Date; import java.util.Calendar; import java.util.GregorianCalendar; public class TestCanlendar { public static void main(String[] args) { Calendar c=new GregorianCalendar(); //设置Calendar的年月日 c.set() //设置方法1 c.set(2020,1,20,12,23,34); //设置方法2 c.set(Calendar.YEAR,2019); c.set(Calendar.MONTH,1); c.set(Calendar.DATE, 28);//日 DATE c.set(Calendar.HOUR_OF_DAY,8);//小时 HOUR_OF_DAY c.set(Calendar.MINUTE,9); c.set(Calendar.SECOND,2); c.set(Calendar.DAY_OF_WEEK,4);//星期几 DAY_OF_WEEK //获取Calendar的年月日 c.get() System.out.println(c.get(Calendar.YEAR)); System.out.println(c.get(Calendar.MONTH)); System.out.println(c.get(Calendar.DATE)); System.out.println(c.get(Calendar.HOUR_OF_DAY)); System.out.println(c.get(Calendar.MINUTE)); System.out.println(c.get(Calendar.SECOND)); System.out.println(c.get(Calendar.DAY_OF_WEEK)); //Canlendar-->Date c.getTime() Date date=c.getTime(); System.out.println(date);//Thu Feb 28 12:23:34 CST 2019 //Date-->Calendar c.setTime() Date date1=new Date(1987600000); c.setTime(date1); System.out.println(c.get(Calendar.YEAR));//1970 //测试日期计算 add c.add(Calendar.YEAR, 20); c.add(Calendar.YEAR, -20); System.out.println(c.get(Calendar.YEAR));//1970 } }
标签:calendar reg cond 星期几 方法 system ring project add
原文地址:https://www.cnblogs.com/hapyygril/p/12442699.html