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

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

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

    隨筆-314  評論-209  文章-0  trackbacks-0

    package com.hoten.util;

    import java.util.*;
    import java.io.*;

    /**
     * <p>Title: Time  </p>
     * <p>Description: </p>
     *      此類主要用來取得本地系統(tǒng)的系統(tǒng)時間并用下面5種格式顯示
     *              1. YYMMDDHH         8位
     *              2. YYMMDDHHmm       10位
     *              3. YYMMDDHHmmss     12位
     *              4. YYYYMMDDHHmmss   14位
     *              5. YYMMDDHHmmssxxx  15位 (最后的xxx 是毫秒)
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: c-platform</p>
     * @author WuJiaQian
     * @version 1.0
     */
    public class CTime {
         public static final int YYMMDDhhmmssxxx = 15;
         public static final int YYYYMMDDhhmmss = 14;
         public static final int YYMMDDhhmmss = 12;
         public static final int YYMMDDhhmm = 10;
         public static final int YYMMDDhh = 8;

           /**
          * 取得本地系統(tǒng)的時間,時間格式由參數(shù)決定
          * @param format 時間格式由常量決定
          * @return String 具有format格式的字符串
          */
         public static String getTime(int format) {
              StringBuffer cTime = new StringBuffer(15);
              Calendar time = Calendar.getInstance();
              int miltime = time.get(Calendar.MILLISECOND);
              int second = time.get(Calendar.SECOND);
              int minute = time.get(Calendar.MINUTE);
              int hour = time.get(Calendar.HOUR_OF_DAY);
              int day = time.get(Calendar.DAY_OF_MONTH);
              int month = time.get(Calendar.MONTH) + 1;
              int year = time.get(Calendar.YEAR);
              time = null;
              if (format != 14) {
                   if (year >= 2000) year = year - 2000;
                   else year = year - 1900;
              }
              if (format >= 2) {
                   if (format == 14) cTime.append(year);
                   else cTime.append(getFormatTime(year, 2));
              }
              if (format >= 4)
                   cTime.append(getFormatTime(month, 2));
              if (format >= 6)
                   cTime.append(getFormatTime(day, 2));
              if (format >= 8)
                   cTime.append(getFormatTime(hour, 2));
              if (format >= 10)
                   cTime.append(getFormatTime(minute, 2));
              if (format >= 12)
                   cTime.append(getFormatTime(second, 2));
              if (format >= 15)
                   cTime.append(getFormatTime(miltime, 3));
              return cTime.toString().trim();
         }

         /**
          * 產(chǎn)生任意位的字符串
          * @param time int 要轉(zhuǎn)換格式的時間
          * @param format int 轉(zhuǎn)換的格式
          * @return String 轉(zhuǎn)換的時間
          */

         public synchronized static String getYearAdd(int format, int iyear) {
              StringBuffer cTime = new StringBuffer(10);
              Calendar time = Calendar.getInstance();
              time.add(Calendar.YEAR, iyear);
              int miltime = time.get(Calendar.MILLISECOND);
              int second = time.get(Calendar.SECOND);
              int minute = time.get(Calendar.MINUTE);
              int hour = time.get(Calendar.HOUR_OF_DAY);
              int day = time.get(Calendar.DAY_OF_MONTH);
              int month = time.get(Calendar.MONTH) + 1;
              int year = time.get(Calendar.YEAR);
              if (format != 14) {
                   if (year >= 2000) year = year - 2000;
                   else year = year - 1900;
              }
              if (format >= 2) {
                   if (format == 14) cTime.append(year);
                   else cTime.append(getFormatTime(year, 2));
              }
              if (format >= 4)
                   cTime.append(getFormatTime(month, 2));
              if (format >= 6)
                   cTime.append(getFormatTime(day, 2));
              if (format >= 8)
                   cTime.append(getFormatTime(hour, 2));
              if (format >= 10)
                   cTime.append(getFormatTime(minute, 2));
              if (format >= 12)
                   cTime.append(getFormatTime(second, 2));
              if (format >= 15)
                   cTime.append(getFormatTime(miltime, 3));
              return cTime.toString();
         }

         /**
          * 產(chǎn)生任意位的字符串
          * @param time int 要轉(zhuǎn)換格式的時間
          * @param format int 轉(zhuǎn)換的格式
          * @return String 轉(zhuǎn)換的時間
          */
         private static String getFormatTime(int time, int format) {
              StringBuffer numm = new StringBuffer(format);
              int length = String.valueOf(time).length();

              if (format < length)return null;

              for (int i = 0; i < format - length; i++) {
                   numm.append("0");
              }
              numm.append(time);
              return numm.toString().trim();
         }

         /**
          * 本函數(shù)主要作用是返回當(dāng)前年份
          * @param len int 要轉(zhuǎn)換年的位數(shù)
          * @return String 處理后的年 
          */

         public static String getYear(int len) {
              Calendar time = Calendar.getInstance();
              int year = time.get(Calendar.YEAR);
              String djyear = Integer.toString(year);
              if (len == 2) {
                   djyear = djyear.substring(2);
              }
              return djyear;
         }

         /*
            #本函數(shù)作用是返回當(dāng)前月份(2位)
          */
         public static String getMonth() {
              Calendar time = Calendar.getInstance();
              int month = time.get(Calendar.MONTH) + 1;
              String djmonth = "";
              if (month < 10) {
                   djmonth = "0" + Integer.toString(month);
              }
              else {
                   djmonth = Integer.toString(month);
              }
              return djmonth;
         }
         
          /*
            #本函數(shù)作用是返回上個月份(2位)
          */
         public static String getPreMonth() {
             Calendar time = Calendar.getInstance();
        int month = time.get(Calendar.MONTH);
        if (month == 0) month = 12;

        String djmonth = "";
             if (month < 10) {
                 djmonth = "0" + Integer.toString(month);
             }
             else {
                 djmonth = Integer.toString(month);
             }
             return djmonth;
         }

         /*
            #本函數(shù)主要作用是返回當(dāng)前天數(shù)
          */
         public static String getDay() {
              Calendar time = Calendar.getInstance();
              int day = time.get(Calendar.DAY_OF_MONTH);
              String djday = "";
              if (day < 10) {
                   djday = "0" + Integer.toString(day);
              }
              else {
                   djday = Integer.toString(day);
              }
              return djday;
         }

         /*
            本函數(shù)作用是返回當(dāng)前小時
          */
         public static String getHour() {
              Calendar time = Calendar.getInstance();
              int hour = time.get(Calendar.HOUR_OF_DAY);
              String djhour = "";
              if (hour < 10) {
                   djhour = "0" + Integer.toString(hour);
              }
              else {
                   djhour = Integer.toString(hour);
              }
              return djhour;
         }

         /*
            #本函數(shù)作用是返回當(dāng)前分鐘
          */
         public static String getMin() {
              Calendar time = Calendar.getInstance();
              int min = time.get(Calendar.MINUTE);
              String djmin = "";
              if (min < 10) {
                   djmin = "0" + Integer.toString(min);
              }
              else {
                   djmin = Integer.toString(min);
              }
              return djmin;
         }

         /*
            #本函數(shù)的主要功能是格式化時間,以便于頁面顯示
            #time 時間 可為6位、8位、12位、15位
            #return 返回格式化后的時間
            #6位 YY年MM月DD日
            #8位 YYYY年MM月DD日
            #12位 YY年MM月DD日 HH:II:SS
            #15位 YY年MM月DD日 HH:II:SS:CCC
          */
         public static String formattime(String time) {
              int length = 0;
              length = time.length();
              String renstr = "";
              switch (length) {
                   case 6:
                        renstr = time.substring(0, 2) + "年" + time.substring(2, 4) +
                            "月" + time.substring(4) + "日";
                        break;
                   case 8:
                        renstr = time.substring(0, 4) + "年" + time.substring(4, 6) +
                            "月" + time.substring(6, 8) + "日";
                        break;
                   case 12:
                        renstr = time.substring(0, 2) + "年" + time.substring(2, 4) +
                            "月" + time.substring(4, 6) + "日 " + time.substring(6, 8) +
                            "時" + time.substring(8, 10) + "分" +
                            time.substring(10, 12) + "秒";
                        break;
                   case 14:
                        renstr = time.substring(0, 4) + "-" + time.substring(4, 6) +
                            "-" + time.substring(6, 8) + " " + time.substring(8, 10) +
                            ":" + time.substring(10, 12) + ":" +
                            time.substring(12, 14) + "";
                        break;
                   case 15:
                        renstr = time.substring(0, 2) + "年" + time.substring(2, 4) +
                            "月" + time.substring(4, 6) + "日 " + time.substring(6, 8) +
                            ":" + time.substring(8, 10) + ":" +
                            time.substring(10, 12) + ":" + time.substring(12);
                        break;
                   default:
                        renstr = time.substring(0, 2) + "年" + time.substring(2, 4) +
                            "月" + time.substring(4) + "日";
                        break;
              }
              return renstr;
         }
    }

    posted on 2006-09-19 19:32 xzc 閱讀(303) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲国产精品不卡在线电影| 亚洲一区日韩高清中文字幕亚洲| 亚洲综合成人网在线观看| 一区在线免费观看| 亚洲中文字幕无码爆乳av中文| 污网站在线免费观看| 亚洲国产日韩成人综合天堂| 无码的免费不卡毛片视频| 亚洲av再在线观看| 有色视频在线观看免费高清在线直播| 亚洲福利精品一区二区三区| 一级一片免费视频播放| 国产亚洲精品自在线观看| 免费视频一区二区| 亚洲毛片一级带毛片基地| 成人免费看吃奶视频网站| 春暖花开亚洲性无区一区二区 | 亚洲日本国产乱码va在线观看| 最近免费中文字幕高清大全| 亚洲一欧洲中文字幕在线| 午夜毛片不卡高清免费| 免费高清A级毛片在线播放| 亚洲精品卡2卡3卡4卡5卡区| 久久99国产乱子伦精品免费| 77777亚洲午夜久久多喷| 亚洲国产91精品无码专区| 香蕉免费一级视频在线观看| 亚洲视频一区在线观看| 性做久久久久免费看| 中国一级毛片视频免费看| 亚洲成人福利网站| 亚洲第一成人影院| 中文字幕免费在线| 国产精品亚洲一区二区三区| 亚洲爆乳无码一区二区三区| 又粗又大又黑又长的免费视频| 国产亚洲精彩视频| 91在线精品亚洲一区二区| 国产又长又粗又爽免费视频| 免费成人在线电影| 国产成人综合亚洲一区|