当前页面: 开发资料首页 → J2SE 专题 → java如何取得7天前的系统时间?
java如何取得7天前的系统时间?
摘要: java如何取得7天前的系统时间?
如题.急
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
cal.add(Calendar.DATE, -7);
System.out.println(cal.getTime());
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH,-7);//关键是这个7天前....
SimpleDateFormat sdf = new SimpleDateFormat(-#34;yyyy-MM-dd hh:mm:ss-#34;);
System.out.println(sdf.format(c.getTime()));
上面的对哟,只不过把SimpleDateFormat sdf = new SimpleDateFormat(-#34;yyyy-MM-dd hh:mm:ss-#34;);中的小写hh变成大写HH就可以表示成24小时制了。