package com.linying.util;

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

          /**
           * 用于日期時間處理的工具類
           * 
          @author sitinspring
           *
           
          */
          public final class TimeUtil {
              
          private TimeUtil() {

              }
              
              
          /**
               * 取得當前日期時間
               
          */
              
          public static String getShortCurrDateTime() {
                  Date date 
          = new Date();
                  Format formatter 
          = new SimpleDateFormat("yyyyMMddHHmmss");
                  
          return formatter.format(date);
              }
              
              
          /**
               * 取得當前日期時間
               
          */
              
          public static String getCurrDateTime() {
                  Date date 
          = new Date();
                  Format formatter 
          = new SimpleDateFormat("yyyy年MM月dd日HH時mm分ss秒");
                  
          return formatter.format(date);
              }

           
              
          /**
               * 取得當前日期
               
          */
              
          public static String getCurrentDate() {
                  Date date 
          = new Date();
                  Format formatter 
          = new SimpleDateFormat("yyyy.MM.dd");
                  
          return formatter.format(date);
              }
              
              
          /**
               * 取得當前年度+月份
               
          */
              
          public static String getCurrentYearMonth() {
                  Date date 
          = new Date();
                  Format formatter 
          = new SimpleDateFormat("yyyy.MM");
                  
          return formatter.format(date);
              }
              
              
          /**
               * 取得當前日期
               
          */
              
          public static String getCurrDate() {
                  Date date 
          = new Date();
                  Format formatter 
          = new SimpleDateFormat("yyyy年MM月dd日");
                  
          return formatter.format(date);
              }

              
          /**
               * 取得當前時間
               
          */
              
          public static String getCurrTime() {
                  Date date 
          = new Date();
                  Format formatter 
          = new SimpleDateFormat("HH時mm分ss秒");
                  
          return formatter.format(date);
              }

              
          /**
               * 取得當前年月
               
          */
              
          public static String getCurrMonth() {
                  Date date 
          = new Date();
                  Format formatter 
          = new SimpleDateFormat("yyyy年MM月");
                  
          return formatter.format(date);
              }

              
          /**
               * 在年月的基礎上加上或減去月份得到新年月
               
          */
              @SuppressWarnings(
          "deprecation")
              
          public static String getChangedDate(String strMonth,int monthCount) {
                  SimpleDateFormat myFormatter 
          = new SimpleDateFormat("yyyy.MM");

                  
          try {
                      java.util.Date date 
          = myFormatter.parse(strMonth);
                      date.setMonth(date.getMonth()
          +monthCount);
                                  
                      Format formatter 
          = new SimpleDateFormat("yyyy.MM");
                      
          return formatter.format(date);
                  } 
          catch (Exception ex) {
                      
          return null;
                  }
              }

              
          /**
               * 取得一個月中有多少天
               * 
               * 
          @param strMonth
               * 
          @return
               
          */
              
          public static int getDaysInAMonth(String strMonth) {
                  String[] arr
          =strMonth.split("[.]");
                  Calendar cal 
          = new GregorianCalendar(Integer.parseInt(arr[0]),Integer.parseInt(arr[1])-11);
                  
          int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); 
                  
          return days;
                  
              }
              
              
          /**
               * 取得每個月的第一天是周幾
               * 
          @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;
              }
          }
          posted on 2010-05-29 17:27 Ying-er 閱讀(318) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 九龙城区| 巴青县| 翼城县| 蒙自县| 陈巴尔虎旗| 阜新| 浑源县| 琼中| 普洱| 塔城市| 绵阳市| 南京市| 乌兰察布市| 景宁| 连云港市| 司法| 阳江市| 麦盖提县| 浦北县| 玉田县| 民县| 大理市| 正宁县| 富阳市| 阳山县| 南江县| 南投县| 贡山| 阿荣旗| 澜沧| 镇原县| 广元市| 衡阳县| 青州市| 逊克县| 清徐县| 昌宁县| 建阳市| 乌兰浩特市| 张家口市| 永善县|