Java中日期的获得与使用

时间:2022-04-05 18:08:41

Calendar的使用:

Calendar.Builder builder =newCalendar.Builder();

Calendar calendar1 = builder.build();

Date date = calendar.getTime();

 

 

Calendar中我们则能够获得较为直观的年月日信息:

int year =calendar.get(Calendar.YEAR);

 

int month=calendar.get(Calendar.MONTH)+1;

 

int day=calendar.get(Calendar.DAY_OF_MONTH);

 

int hour=calendar.get(Calendar.HOUR_OF_DAY);

 

int minute =calendar.get(Calendar.MINUTE);

 

int seconds=calendar.get(Calendar.SECOND);   

 

SimpleDateFormat用来进行简单的数据格式化转化操作

Date dNow = new Date( );

SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");