<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>
     *      此類主要用來取得本地系統的系統時間并用下面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;

           /**
          * 取得本地系統的時間,時間格式由參數決定
          * @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();
         }

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

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

         /**
          * 產生任意位的字符串
          * @param time int 要轉換格式的時間
          * @param format int 轉換的格式
          * @return String 轉換的時間
          */
         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();
         }

         /**
          * 本函數主要作用是返回當前年份
          * @param len int 要轉換年的位數
          * @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;
         }

         /*
            #本函數作用是返回當前月份(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;
         }
         
          /*
            #本函數作用是返回上個月份(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;
         }

         /*
            #本函數主要作用是返回當前天數
          */
         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;
         }

         /*
            本函數作用是返回當前小時
          */
         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;
         }

         /*
            #本函數作用是返回當前分鐘
          */
         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;
         }

         /*
            #本函數的主要功能是格式化時間,以便于頁面顯示
            #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片在线观看| 亚洲午夜未满十八勿入| 性xxxx视频播放免费| 丁香花在线视频观看免费 | 一区二区在线免费观看| 人妻仑乱A级毛片免费看| 亚洲愉拍一区二区三区| 久久精品国产亚洲av高清漫画| 亚洲AV网站在线观看| 国产精品免费观看久久| 国产成人精品久久免费动漫| a毛片免费在线观看| 搜日本一区二区三区免费高清视频 | 亚洲专区中文字幕| 久久久久亚洲av无码专区 | 国产免费网站看v片在线| 一区二区视频在线免费观看| 国产成人高清亚洲一区91| 337P日本欧洲亚洲大胆艺术图| 亚洲日产2021三区| 亚洲欧洲春色校园另类小说| 亚洲最新视频在线观看| 亚洲天天做日日做天天欢毛片| 亚洲国产精华液网站w| 综合亚洲伊人午夜网| 国产日韩成人亚洲丁香婷婷| 亚洲欧洲中文日韩av乱码| 亚洲国产精品成人一区| 亚洲国产成人久久综合野外| 亚洲国产精品成人一区| 亚洲乱码中文字幕手机在线| 国产亚洲精品免费视频播放| 亚洲色中文字幕无码AV| 亚洲成AV人在线观看天堂无码| 亚洲国产精品福利片在线观看| 亚洲国产另类久久久精品小说 | 免费国产黄网站在线观看| 日韩在线永久免费播放| 最近中文字幕高清免费中文字幕mv| 99精品国产成人a∨免费看| 巨波霸乳在线永久免费视频 |