posts - 33,  comments - 17,  trackbacks - 0
           1/**
           2 * 取得服務器當前的各種具體時間
           3 * 回車:日期時間
           4 */

           5
           6import java.util.*;
           7
           8public class GetNowDate{
           9    Calendar  calendar = null;
          10  
          11    public GetNowDate(){
          12        calendar = Calendar.getInstance();
          13        calendar.setTime(new Date());
          14    }

          15  
          16    public int getYear(){
          17        return calendar.get(Calendar.YEAR);
          18    }

          19  
          20    public int getMonth(){
          21        return 1 + calendar.get(Calendar.MONTH);
          22    }

          23  
          24    public int getDay(){
          25        return calendar.get(Calendar.DAY_OF_MONTH);
          26    }

          27  
          28    public int getHour(){
          29        return calendar.get(Calendar.HOUR_OF_DAY);
          30    }

          31    
          32    public int getMinute(){
          33        return calendar.get(Calendar.MINUTE);
          34    }

          35  
          36    public int getSecond(){
          37        return calendar.get(Calendar.SECOND);
          38    }

          39    
          40    public String getDate(){
          41        return getMonth()+"/"+getDay()+"/"+getYear();
          42    }

          43  
          44    public String getTime(){
          45        return getHour()+":"+getMinute()+":"+getSecond();
          46    }

          47  
          48    public String getDate2(){
          49        String yyyy="0000", mm="00", dd="00";
          50        yyyy = yyyy + getYear();
          51        mm   = mm   + getMonth();
          52        dd   = dd + getDay();
          53        yyyy = yyyy.substring(yyyy.length()-4);
          54        mm   = mm.substring(mm.length()-2);
          55        dd   = dd.substring(dd.length()-2);
          56        return yyyy + "/" + mm + "/" +  dd;
          57    }

          58  
          59    public String getTime2(){
          60        String hh="00", mm="00", ss="00";
          61        hh = hh + getHour();
          62        mm = mm + getMinute();
          63        ss = ss + getSecond();
          64        hh = hh.substring(hh.length()-2, hh.length());
          65        mm = mm.substring(mm.length()-2, mm.length());
          66        ss = ss.substring(ss.length()-2, ss.length());
          67        return hh + ":" + mm + ":" + ss;
          68    }

          69}
          posted on 2008-07-23 17:34 scea2009 閱讀(105) 評論(0)  編輯  收藏

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


          網站導航:
           

          <2008年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          PL/SQL存儲過程與函數

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 山丹县| 许昌市| 高邑县| 宜春市| 石城县| 永靖县| 长沙市| 龙陵县| 阿拉善左旗| 万源市| 彰化市| 汪清县| 缙云县| 铅山县| 崇左市| 寿光市| 六枝特区| 靖远县| 米林县| 门头沟区| 托里县| 城固县| 苍山县| 孟村| 墨竹工卡县| 金昌市| 长丰县| 花莲县| 灌云县| 客服| 临桂县| 定边县| 五常市| 荣成市| 普安县| 镇雄县| 察隅县| 石棉县| 西和县| 石柱| 平凉市|