java 获取日期正常的话 一般都用Calendar 类来操作,但是本人脑子笨老是忘记,所以就用SimpleDateFormat来简单处理,如下:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//yyyy-MM-dd HH:mm:ss 看个人需求
Date date = null;
Date nowDate=new Date();
try {
date = simpleDateFormat.parse(simpleDateFormat.format(new Date(nowDate.getTime()-1000*60*60*24)));// 你想多少天就是多少天 //获取 星期 不建议用该方法 请使用Calendar.DAY_OF_WEEK
} catch (ParseException e) {
e.printStackTrace();
}
网友评论