<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免费| 免费中文字幕视频| 免费a级毛片无码a∨蜜芽试看| 亚洲精品在线电影| 歪歪漫画在线观看官网免费阅读| 亚洲精品无码久久久久秋霞| 又粗又黄又猛又爽大片免费 | 国产亚洲福利一区二区免费看| 一区国严二区亚洲三区| 日本免费一区二区久久人人澡| 亚洲国产人成在线观看| 国产免费131美女视频| 国产精品免费看久久久| 国产精品极品美女自在线观看免费 | 免费的一级片网站| 9久热这里只有精品免费| 亚洲免费视频网址| 99ri精品国产亚洲| 亚洲av无码成人精品区在线播放| 97视频免费观看2区| 在线看亚洲十八禁网站| 亚洲日韩一中文字暮| 亚洲а∨天堂久久精品9966| 国产亚洲高清不卡在线观看| 精品国产精品久久一区免费式| 色se01短视频永久免费| 成年女人A毛片免费视频| 亚洲日本国产综合高清| 亚洲国产成人久久综合一区| 久久久久亚洲AV无码永不| 亚洲国产精品一区| 亚洲精品成人片在线观看| 久久久久久国产精品免费免费| 精品无码免费专区毛片| 99久久国产精品免费一区二区| 成人精品国产亚洲欧洲| 亚洲一区二区三区在线观看蜜桃 | 亚洲熟妇无码一区二区三区| 亚洲AV无码AV男人的天堂| 亚洲综合区小说区激情区| 在线观看免费精品国产|