JAVA: 如何显示比当前DATE时间,提前一个月的时间 还有提前20天

源:http://zhidao.baidu.com/link?url=3BGKZ_Ipjmuze5UCcuzVY1lFwjpoQJaiIZ6buT_5MXLZz22HtgY-XCv0vkBPRcysROCplCcCz7Jfc5JWjH8II_ 
评:
  Date date = new Date();//当前日期
  SimpleDate()Format sdf = new SimpleDateFormat("yyyy/MM/dd");//格式化对象
  Calendar calendar = Calendar.getInstance();//日历对象
  calendar.setTime(date);//设置当前日期
  calendar.add(Calendar.MONTH, -1);//月份减一
  System.out.println(sdf.format(calendar.getTime()));//输出格式化的日期


ca.add(Calendar.DAY_OF_MONTH, -20);//提前20天
Calendar.DAY_OF_MONTH 处设定你的特定时间。

猜你喜欢

转载自mauersu.iteye.com/blog/1997489