public class TestDate {
?
?????? public String yesteday() {
??????????????
//?????????? 當(dāng)前時間
???????????????Calendar cal = Calendar.getInstance();
???????????//??日期的DATE減去10??就是往后推10 天 同理 +10 就是往后推十天
????????????? cal.add(Calendar.DATE, -10);
?
????????????? SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
?????????????
????????????? String str = sf.format(cal.getTime());
?????????????
????????????? System.out.print(str);
????????????? return str;
?????? }
?
?????? public static void main(String args[]) {
????????????? new TestDate().yesteday();
?????? }
?
}
記的用DATE 類的時候要先得到當(dāng)前的年,月,日,再將日數(shù)減或加.再new Date(year,month,day);
有了?Calendar 感覺方便多了.
posted on 2006-03-18 07:52
square 閱讀(2755)
評論(1) 編輯 收藏