posts - 11,  comments - 9,  trackbacks - 0


          public class TestDate {

          ?

          ?????? public String yesteday() {

          ??????????????
          //?????????? 當前時間
          ???????????????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 類的時候要先得到當前的年,月,日,再將日數減或加.再new Date(year,month,day);
          有了?Calendar 感覺方便多了.

          posted on 2006-03-18 07:52 square 閱讀(2758) 評論(1)  編輯  收藏


          FeedBack:
          # re: 用 java.util.Calendar 得到前幾天的日期
          2013-09-13 10:18 | ouyangshixiong
          錯的。不要上當。  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年9月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章檔案

          收藏夾

          IBM developerworks JAVA

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南木林县| 莲花县| 鹤峰县| 玉溪市| 乡城县| 龙川县| 新闻| 陇川县| 长治县| 枣庄市| 仁寿县| 永宁县| 宜春市| 方城县| 油尖旺区| 汤阴县| 吴堡县| 周至县| 云龙县| 三台县| 乐至县| 新兴县| 湘潭市| 嵊州市| 牙克石市| 区。| 司法| 湄潭县| 广平县| 凉城县| 梓潼县| 上饶市| 威宁| 通山县| 宜君县| 南昌市| 白玉县| 前郭尔| 苏州市| 邓州市| 施秉县|