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存儲過程與函數

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 樟树市| 洪湖市| 星子县| 岫岩| 南汇区| 集贤县| 潍坊市| 本溪市| 晋江市| 祥云县| 成安县| 普宁市| 甘孜县| 龙南县| 福鼎市| 定南县| 娄底市| 莲花县| 萝北县| 阜康市| 元阳县| 新野县| 仙居县| 大兴区| 泽库县| 平顶山市| 霍州市| 新田县| 渭南市| 漳平市| 海门市| 淮北市| 高尔夫| 桃源县| 盘锦市| 澄江县| 通化县| 郓城县| 桓台县| 昭平县| 蓝山县|