黑豆熊——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 黑豆熊 阅读(58320) 评论(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

顶  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: