今天项目中要用到5分钟前的时间,在网上找了很久才挖掘出这几句代码:
对时分秒天月年都能操作,很方便。。所以分享一下
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date = sdf.parse("2012-05-29 11:40:00");
int minutes = date.getMinutes();
minutes = minutes-5;
date.setMinutes(minutes);
System.out.println(sdf.format(date));
} catch (ParseException e) {
e.printStackTrace();
}
对时分秒天月年都能操作,很方便。。所以分享一下