zoukankan      html  css  js  c++  java
  • 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); 
        }
    }   
  • 相关阅读:
    vc6编译64位程序
    WebBrowser 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
    python中subprocess.Popen的使用
    对AutoResetEvent和ManualResetEvent的理解
    Vue-Socket.io跨域问题 has been blocked by CORS policy: No 'Access-Control-Allow-Origin' Mentalflow解决思路
    如何使用GoLand debug
    Python协程与JavaScript协程的对比
    [基础] TCP小结
    导出字段脚本
    永恒之蓝——windows server 2003 漏洞
  • 原文地址:https://www.cnblogs.com/huapox/p/3516103.html
Copyright © 2011-2022 走看看