Java 日期获取

public static String getDateBefore(int day) {
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  Calendar now = Calendar.getInstance(); 
  now.setTime(new Date());
  now.add(Calendar.DATE, day); //day=-1表示得到昨天日期
  return sdf.format(now.getTime()) ;

}

 

posted @ 2014-07-09 11:14  箜篌  阅读(149)  评论(0编辑  收藏  举报