标签:print 通过 form strong time() 特定 code value 字段
Calendar.YEAR——年份
Calendar.MONTH——月份
Calendar.DATE——日期
Calendar.DAY_OF_MONTH——日期,和上面的字段意义相同
Calendar.HOUR——12小时制的小时
Calendar.HOUR_OF_DAY——24小时制的小时
Calendar.MINUTE——分钟
Calendar.SECOND——秒
Calendar.DAY_OF_WEEK——星期几
//获取当前时间的 Calendar 对象 Calendar.getInstance()
Calendar calendar = Calendar.getInstance();
//获取特定日期的 Calendar 对象
//1.calendar.set(filed,value);
calendar.set(Calendar.YEAR,1995);//设置年
calendar.set(Calendar.MONTH,4-1);//设置月 需比实际月份小一
calendar.set(Calendar.DATE,14);//设置日
calendar.set(Calendar.HOUR_OF_DAY,15);//设置时
calendar.set(Calendar.MINUTE,30);//设置分
calendar.set(Calendar.SECOND,30);//设置秒
//通过Calendar对象,获得Date对象 calendar.getTime()
Date setTime = calendar.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = sdf.format(setTime);
System.out.println(format);//1995-05-14 15:30:30
//2.calendar.set(year,month-1,day,hour,minute,second);
calendar.set(1995,3-1,15,23,59,59);
String format1 = sdf.format(calendar.getTime());
System.out.println(format1); //1995-03-15 23:59:59
//3.calendar.setTime(Date date) 通过Date对象获取Calendar对象
calendar.setTime(setTime);
System.out.println(sdf.format(calendar.getTime()));
//1995-05-14 15:30:30
//4.calendar.setTimeInMillis(long TimeMillis) 通过毫秒数获取Calendar对象
calendar.setTimeInMillis(System.currentTimeMillis());
System.out.println(sdf.format(calendar.getTime()));
//2020-11-22 14:50:19
//1.获得Date对象 calendar.getTime()
Date setTime = calendar.getTime();
//2.获取毫秒数 calendar.getTimeInMillis()
long timeInMillis = calendar.getTimeInMillis();
//3.获取年,月,日,时,分,秒等属性 calendar.get(filed)
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH)+1;//month需加1
int day = calendar.get(Calendar.DATE);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
标签:print 通过 form strong time() 特定 code value 字段
原文地址:https://www.cnblogs.com/jqccan/p/14020577.html