Calendar与Date转换
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开始。