zoukankan      html  css  js  c++  java
  • java的时间格式化

    JAVA格式化时间日期

    转自:http://www.blogjava.net/youling/archive/2008/11/05/238759.html

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

  • 相关阅读:
    .NET下的并行开发
    .NET下单文件的上传处理
    .NET下dropdownlist的基本操作
    [Python3网络爬虫开发实战] 3.1.1-发送请求
    [Python3网络爬虫开发实战] 3.1.2-处理异常
    [Python3网络爬虫开发实战] 3.1-使用urllib
    [Python3网络爬虫开发实战] 2.4-会话和Cookies
    [Python3网络爬虫开发实战] 2.5-代理的基本原理
    [Python3网络爬虫开发实战] 2.3-爬虫的基本原理
    [Python3网络爬虫开发实战] 2.2-网页基础
  • 原文地址:https://www.cnblogs.com/_programmer/p/3366148.html
Copyright © 2011-2022 走看看