<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 此號已被刪 閱讀(1273) 評論(0)  編輯  收藏 所屬分類: JAVA

    導航

    統計

    常用鏈接

    留言簿(8)

    隨筆分類(83)

    隨筆檔案(78)

    文章檔案(2)

    相冊

    收藏夾(7)

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 精品亚洲一区二区三区在线观看 | 亚洲精品WWW久久久久久| 亚洲免费观看在线视频| 无码精品人妻一区二区三区免费看| 中文字幕第13亚洲另类| 免费人成又黄又爽的视频在线电影| 波多野结衣久久高清免费 | 7777久久亚洲中文字幕| 国产免费毛不卡片| 亚洲香蕉在线观看| 在线观看免费大黄网站| 亚洲1区2区3区精华液| 国产又粗又猛又爽又黄的免费视频| 久久亚洲中文字幕无码| 亚洲国产中文字幕在线观看| 一区二区三区在线免费观看视频| 亚洲成A∨人片天堂网无码| av午夜福利一片免费看久久| 久久青青成人亚洲精品| 91成人在线免费视频| 亚洲日韩AV一区二区三区四区| 日韩高清在线免费看| 一级做a爰全过程免费视频毛片| 亚洲色偷偷狠狠综合网| 国产一区二区免费| 亚洲av日韩av无码av| 四虎影视精品永久免费| a级日本高清免费看| 亚洲人成网站在线观看播放青青| 免费观看a级毛片| 中国好声音第二季免费播放| 色婷婷亚洲十月十月色天| 天天摸天天操免费播放小视频| 女bbbbxxxx另类亚洲| 久久亚洲精品中文字幕无码| 99精品国产免费久久久久久下载| 全黄A免费一级毛片| 亚洲伊人久久大香线蕉苏妲己| 免费无码又爽又刺激高潮的视频| A毛片毛片看免费| 涩涩色中文综合亚洲|