package com.linying.util;

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

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

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

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

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

              
          /**
               * 取得當(dāng)前年月
               
          */
              
          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;
                  }
              }

              
          /**
               * 取得一個(gè)月中有多少天
               * 
               * 
          @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;
                  
              }
              
              
          /**
               * 取得每個(gè)月的第一天是周幾
               * 
          @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 閱讀(319) 評(píng)論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 介休市| 清河县| 尖扎县| 紫阳县| 吴川市| 绥芬河市| 娄底市| 扬中市| 新蔡县| 增城市| 黄冈市| 恩施市| 射阳县| 乌拉特前旗| 易门县| 临桂县| 二连浩特市| 五莲县| 浙江省| 台湾省| 陇川县| 崇义县| 额尔古纳市| 甘泉县| 台前县| 同德县| 富锦市| 通州区| 米林县| 平定县| 团风县| 寻甸| 漯河市| 来宾市| 普格县| 宝鸡市| 乌兰县| 新平| 托克逊县| 满洲里市| 辽中县|