欢迎留言一起讨论,共同学习!
1.字符串转换成日期类型
@Test
public void test1() {
String dateString = "2017-12-28 21:14:00";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateTime = null;
try {
dateTime = da( dateString );
} catch (ParseException e) {
dateTime = null;
}// END TRY
Sy(dateTime);//Thu Dec 28 21:14:00 GMT+08:00 2017
}
2.取得前几天的日期
@Test
public void test1() {
Date d = new Date();//获取当前时间 Mon Jan 04 10:10:38 GMT+08:00 2018
int day = 3;//表示前3天
Calendar now = Calendar.getInstance();
now.setTime(d);
now.se, now.ge) - day);
Sy());//Mon Jan 01 10:10:38 GMT+08:00 2018
}