Calendar转成Date类型

1. Calendar初始化

1  Calendar c = Calendar.getInstance();
2  c.set(2014, 7, 06, 16, 59);

2. 转成Date类型

1 Date startDate = c.getTime();

 

Date转成Calendar类型

1.Date初始化

1 Date date = new Date();

2.转成Calendar类型

1 Calendar cal=Calendar.getInstance();
2 cal.setTime(date);

 

tips:Calendar.set()的方法签名

1 void java.util.Calendar.set(int year, int month, int date, int hourOfDay, int minute)
1 Parameters:
2 year the value used to set the YEAR calendar field.
3 month the value used to set the MONTH calendar field. Month value is 0-based. e.g., 0 for January.
4 date the value used to set the DAY_OF_MONTH calendar field.
5 hourOfDay the value used to set the HOUR_OF_DAY calendar field.
6 minute the value used to set the MINUTE calendar field.

值得注意的是Month是从0开始。

相关文章:

  • 2022-03-10
  • 2021-05-28
  • 2022-02-08
  • 2021-10-14
  • 2021-09-15
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2021-08-12
  • 2021-12-28
  • 2022-01-11
  • 2021-11-13
  • 2021-09-22
相关资源
相似解决方案