<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Natural

     

    列舉Java日歷類Calendar的一些常用方法

     
           在開發時關于日期的用處很多,此處列舉一些常用的方法。
    對于字符串類型的日期"yyyy-mm-dd"和對Calendar類型日期的處理。

     1/**
     2     * 將yyyy-mm-dd格式的字符串日期轉換為Calendar對象
     3     * @param str String
     4     * @reurn Calendar
     5     */

     6    public Calendar getCalendarDate(String str) throws Exception
     7    {
     8        //Calendar c = Calendar.getInstance();
     9        tmp.setTime( new SimpleDateFormat("yyyy-MM-dd").parse(str));
    10        
    11        return tmp;
    12    }

    13    
    14    /**
    15     * 返回輸入的Calendar日期所在星期的星期一的日期
    16     * @param c Calendar
    17     * @return String (yyyy-mm-dd)
    18     */

    19    public String getFirstDayOfWeek(Calendar c)
    20    {
    21        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
    22        
    23        c.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
    24        return formatter.format(tmp.getTime());
    25    }

    26    
    27    /**
    28     * 返回輸入的Calendar日期所在月的第一天的日期
    29     * @param c Calendar
    30     * @return String (yyyy-mm-dd)
    31     */

    32    public String getFirstDayOfMonth(Calendar c)
    33    {
    34        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
    35        
    36        int year = c.get(c.YEAR);
    37        int month = c.get(c.MONTH);
    38        int day = 1;
    39        c.set(year, month, day);
    40        return formatter.format(tmp.getTime());
    41    }

    42    
    43    /**
    44     * 返回該日期的年份
    45     * @param str String (yyyy-mm-dd)
    46     * @return int
    47     * @throws Exception
    48     */

    49    public int getYear(String str) throws Exception
    50    {
    51        Calendar t = Calendar.getInstance();
    52        t.setTime( new SimpleDateFormat("yyyy-MM-dd").parse(str));
    53        return t.get(t.YEAR);
    54    }

    55    
    56    /**
    57     * 返回該日期的月份
    58     * @param str String (yyyy-mm-dd)
    59     * @return int
    60     * @throws Exception
    61     */

    62    public int getMonth(String str) throws Exception
    63    {
    64        Calendar t = Calendar.getInstance();
    65        t.setTime( new SimpleDateFormat("yyyy-MM-dd").parse(str));
    66        return t.get(t.MONTH)+1;
    67    }

    68    
    69    /**
    70     * 返回該日期所在星期是該月的第幾個星期
    71     * @param str String (yyyy-mm-dd)
    72     * @return int
    73     * @throws Exception
    74     */

    75    public int getWeekNumInMonth(String str) throws Exception
    76    {
    77        Calendar t = Calendar.getInstance();
    78        t.setTime( new SimpleDateFormat("yyyy-MM-dd").parse(str));
    79        return t.get(t.WEEK_OF_MONTH);
    80    }

    posted on 2009-07-09 15:37 此號已被刪 閱讀(1264) 評論(0)  編輯  收藏 所屬分類: JAVA

    導航

    統計

    常用鏈接

    留言簿(8)

    隨筆分類(83)

    隨筆檔案(78)

    文章檔案(2)

    相冊

    收藏夾(7)

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲精品麻豆av| 日本免费一区二区三区最新| 亚洲国产午夜福利在线播放| 亚洲国产欧美一区二区三区 | 一个人看www免费高清字幕| 国产又粗又猛又爽又黄的免费视频| 亚洲免费网站在线观看| 曰批全过程免费视频播放网站 | 成人免费在线观看网站| 亚洲综合精品成人| 在线播放高清国语自产拍免费 | 亚洲sss综合天堂久久久| 久久受www免费人成_看片中文| 亚洲AV综合色区无码二区爱AV| 在线观看视频免费完整版| 亚洲6080yy久久无码产自国产| 妞干网免费视频在线观看| 另类小说亚洲色图| 亚洲一区精品伊人久久伊人| 久久精品无码免费不卡| 中文字幕亚洲精品| 久久这里只有精品国产免费10| 亚洲国产精品成人综合色在线| 国产gav成人免费播放视频| 久久九九久精品国产免费直播| 久久夜色精品国产亚洲AV动态图| 91九色老熟女免费资源站| 亚洲AV无码国产精品色| 在线a亚洲v天堂网2018| 免费无码黄网站在线看| 亚洲一区二区三区91| 亚洲成a人片在线观看国产| 亚洲免费人成在线视频观看| 亚洲美女在线观看播放| 在线A级毛片无码免费真人| sss日本免费完整版在线观看| 日本久久久久亚洲中字幕| 卡一卡二卡三在线入口免费| 久久国产乱子伦精品免费午夜| 亚洲国产日韩在线一区| 亚洲国产精品不卡毛片a在线|