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

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

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

    春風博客

    春天里,百花香...

    導航

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

    統計

    公告

    MAIL: junglesong@gmail.com
    MSN: junglesong_5@hotmail.com

    Locations of visitors to this page

    常用鏈接

    留言簿(11)

    隨筆分類(224)

    隨筆檔案(126)

    個人軟件下載

    我的其它博客

    我的鄰居們

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    日期時間處理實用類

    package com.sitinspring.datetime;

    import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;

    /**
     * 日期時間處理實用類
     * 
     * 
    @author sitinspring(junglesong@gmail.com)
     * 
    @since 2008-7-18 上午10:30:15
     * @vsersion 1.00 創建 sitinspring 2008-7-18 上午10:30:15
     
    */

    public final class DateTimeUtil {
        
    private DateTimeUtil() {

        }


        
    /**
         * 以格式format返回表示日期時間的字符串
         * 
         * 
    @param format
         * 
    @return
         
    */

        
    public static String getDateTimeStr(String format) {
            Date date 
    = new Date();
            Format formatter 
    = new SimpleDateFormat(format);
            
    return formatter.format(date);
        }


        
    /**
         * 取得當前日期時間
         * 
         * 
    @return
         
    */

        
    public static String getCurrDateTime() {
            
    return getDateTimeStr("yyyy.MM.dd HH:mm:ss");
        }


        
    /**
         * 取得當前日期,不足兩位前補零
         * 
         * 
    @return
         
    */

        
    public static String getCurrDate() {
            
    return getDateTimeStr("yyyy.MM.dd");
        }


        
    /**
         * 取得當前日期
         * 
         * 
    @return
         
    */

        
    public static String getSimpleCurrDate() {
            
    return getDateTimeStr("yyyy.M.d");
        }


        
    /**
         * 取得當前時間
         * 
         * 
    @return
         
    */

        
    public static String getCurrTime() {
            
    return getDateTimeStr("HH:mm:ss");
        }


        
    /**
         * 取得當前年月
         * 
         * 
    @return
         
    */

        
    public static String getCurrYearMonth() {
            
    return getDateTimeStr("yyyy.MM");
        }


        
    /**
         * 從文本形式日期取得Date日期時間
         * 
         * 
    @param strMonth
         * 
    @return
         
    */

        
    private static Date getDate(String strMonth) {
            SimpleDateFormat myFormatter 
    = new SimpleDateFormat("yyyy.MM.dd");

            
    try {
                java.util.Date date 
    = myFormatter.parse(strMonth);
                
    return date;
            }
     catch (Exception ex) {
                
    return null;
            }

        }


        
    /**
         * 得到兩個文本日期之間的天數
         * 
         * 
    @param startDate
         * 
    @param endDate
         * 
    @return
         
    */

        
    public static long getDaysBetween(String startDate, String endDate) {
            Date dStart 
    = getDate(startDate);
            Date dEnd 
    = getDate(endDate);

            
    return (dEnd.getTime() - dStart.getTime()) / (24 * 60 * 60 * 1000);
        }


        
    /**
         * 取某月的天數,strMonth的格式是"yyyy.MM"
         * 
    @param strMonth
         * 
    @return
         
    */

        
    public static int getDaysInAMonth(String strMonth) {
            String[] arr 
    = strMonth.split("[.]");

            
    // Create a calendar object of the desired month
            Calendar cal = new GregorianCalendar(Integer.parseInt(arr[0]), Integer
                    .parseInt(arr[
    1]) - 11);

            
    // Get the number of days in that month
            int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

            
    return days;
        }


        
    /**
         * 取某月第一天是周幾,strMonth的格式是"yyyy.MM"
         * 
    @param strMonth
         * 
    @return
         
    */

        
    public static int getWeekOfFirstDay(String strMonth) {
            String[] arr 
    = strMonth.split("[.]");

            Calendar xmas 
    = new GregorianCalendar(Integer.parseInt(arr[0]), Integer
                    .parseInt(arr[
    1]) - 11);
            
    int dayOfWeek = xmas.get(Calendar.DAY_OF_WEEK) - 1;
            
    return dayOfWeek;
        }


        
    public static void main(String[] args) {
            System.out.println(
    "當前日期時間為:" + getCurrDateTime());
            System.out.println(
    "當前日期為:" + getCurrDate());
            System.out.println(
    "當前日期為:" + getSimpleCurrDate());
            System.out.println(
    "當前時間為:" + getCurrTime());
            System.out.println(
    "2008.07.05與2008.07.18之間相隔:"
                    
    + getDaysBetween("2008.07.05""2008.07.18"+ "");
            System.out.println(
    "當前年月為:" + getCurrYearMonth());
            System.out.println(
    "本月第一天為周" + getWeekOfFirstDay(getCurrYearMonth()));
            System.out.println(
    "本月有" + getDaysInAMonth(getCurrYearMonth()) + "");
        }

    }

    輸出:
    當前日期時間為:2008.07.18 10:48:57
    當前日期為:
    2008.07.18
    當前日期為:
    2008.7.18
    當前時間為:
    10:48:57
    2008.07.05與2008.07.18之間相隔:13天
    當前年月為:
    2008.07
    本月第一天為周2
    本月有31天

    posted on 2008-07-18 10:52 sitinspring 閱讀(541) 評論(0)  編輯  收藏 所屬分類: Java API

    sitinspring(http://m.tkk7.com)原創,轉載請注明出處.
    主站蜘蛛池模板: 日韩人妻一区二区三区免费| 亚洲乱码日产精品一二三| 亚洲日本VA午夜在线电影| 2019中文字幕免费电影在线播放| 国产天堂亚洲精品| 国产精品玖玖美女张开腿让男人桶爽免费看| 女人18毛片水最多免费观看| 亚洲av无码成人精品区在线播放 | www.av在线免费观看| 全部免费毛片免费播放| 久久久久亚洲Av无码专| 91精品国产免费入口| 亚洲人成网站在线观看青青| 亚洲性猛交xx乱| 一级毛片在线免费视频| 亚洲永久无码3D动漫一区| 免费萌白酱国产一区二区三区| 亚洲av无码无在线观看红杏| 亚洲av无码有乱码在线观看| 95免费观看体验区视频| 亚洲专区一路线二| 99久久精品国产免费| 亚洲mv国产精品mv日本mv| 日韩欧毛片免费视频| 成人婷婷网色偷偷亚洲男人的天堂| 8x网站免费入口在线观看| 亚洲AV综合色区无码二区偷拍| 国产成人aaa在线视频免费观看 | 国产成人免费永久播放视频平台| 男人j进女人p免费视频| 毛片在线免费视频| 久久久无码精品亚洲日韩按摩| 免费看成人AA片无码视频羞羞网| 蜜芽亚洲av无码一区二区三区| 亚洲欧洲∨国产一区二区三区| **真实毛片免费观看| 国产亚洲综合久久| 亚洲另类激情综合偷自拍| 日韩一级免费视频| 免费人成在线观看网站品爱网| 亚洲AV一区二区三区四区|