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);
              }

              
          /**
               * 在年月的基礎(chǔ)上加上或減去月份得到新年月
               
          */
              @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)  編輯  收藏

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 满洲里市| 齐齐哈尔市| 临沭县| 嘉兴市| 望谟县| 苏尼特左旗| 璧山县| 文山县| 馆陶县| 宿州市| 沅陵县| 平南县| 资阳市| 平和县| 陵水| 日喀则市| 南陵县| 武邑县| 巫溪县| 微山县| 松桃| 兰考县| 西盟| 育儿| 瑞昌市| 治多县| 朔州市| 宁乡县| 都江堰市| 西丰县| 桐乡市| 江西省| 金乡县| 易门县| 海兴县| 永昌县| 改则县| 仙居县| 兴城市| 垫江县| 永春县|