黑豆熊——BlogJava

          面對挑戰,我告訴自己:面對是勇氣,積極面對是態度,堅持積極面對是毅力!

          常用鏈接

          統計

          積分與排名

          最新評論

          JAVA格式化時間日期

          import java.util.Date;
          import java.text.DateFormat;


          /**
          * 格式化時間類
          * DateFormat.FULL = 0
          * DateFormat.DEFAULT = 2
          * DateFormat.LONG = 1
          * DateFormat.MEDIUM = 2
          * DateFormat.SHORT = 3
          * @author    Michael
          * @version   1.0, 2007/03/09
          */

          public class Test{
              public static void main(String []args){
                  Date d = new Date();
                  String s;
                   
                  /** Date類的格式: Sat Apr 16 13:17:29 CST 2006 */
                  System.out.println(d);
                   
                  System.out.println("******************************************");  
                 
                  /** getDateInstance() */
                  /** 輸出格式: 2006-4-16 */
                  s = DateFormat.getDateInstance().format(d);
                  System.out.println(s);
                 
                  /** 輸出格式: 2006-4-16 */
                  s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
                  System.out.println(s);
                 
                  /** 輸出格式: 2006年4月16日 星期六 */
                  s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
                  System.out.println(s);
                 
                  /** 輸出格式: 2006-4-16 */
                  s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
                  System.out.println(s);
                 
                  /** 輸出格式: 06-4-16 */
                  s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
                  System.out.println(s);
                 
                  /** 輸出格式: 2006-01-01 00:00:00 */
                  java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                  s = format1.format(new Date());
                  System.out.println(s);
                 
                  /** 輸出格式: 2006-01-01 00:00:00 */
                  System.out.println((new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(new Date()));
                 
                  /** 輸出格式: 20060101000000***/
                  java.text.DateFormat format2 = new java.text.SimpleDateFormat("yyyyMMddhhmmss");
                  s = format2.format(new Date());
                  System.out.println(s);
              }
          }  

          posted on 2008-11-05 10:43 黑豆熊 閱讀(58352) 評論(6)  編輯  收藏

          評論

          # re: JAVA格式化時間日期 2008-12-30 13:22 北京時間

          多謝  回復  更多評論   

          # re: JAVA格式化時間日期[未登錄] 2013-09-04 00:22 過客

          經典總要好評  回復  更多評論   

          # re: JAVA格式化時間日期[未登錄] 2013-09-26 16:18 aaaaa

          多謝  回復  更多評論   

          # re: JAVA格式化時間日期 2013-10-25 12:32 mj

          謝了  回復  更多評論   

          # re: JAVA格式化時間日期 2013-11-25 08:36 曉月

          灰常感謝。  回復  更多評論   

          # re: JAVA格式化時間日期 2014-12-19 09:57 11111

          頂  回復  更多評論   


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


          網站導航:
           
          主站蜘蛛池模板: 高阳县| 姚安县| 伊宁县| 昭平县| 花垣县| 扎赉特旗| 峨边| 漳浦县| 绵竹市| 乌拉特后旗| 棋牌| 苏州市| 凌源市| 旬邑县| 聂荣县| 横山县| 曲周县| 河西区| 同仁县| 工布江达县| 宜州市| 阳新县| 太湖县| 定兴县| 青神县| 南丹县| 密山市| 宕昌县| 灵璧县| 泾源县| 苍南县| 水城县| 石景山区| 彩票| 南召县| 镇康县| 库车县| 苏尼特左旗| 西峡县| 昌乐县| 江陵县|