随笔 - 18, 文章 - 0, 评论 - 8, 引用 - 0
数据加载中……

简单应用日期类

1.自定义格式
   用到java.text.SimpleDateFormat,其中参数如下:
   ss:秒
   mm:分
   hh:小时
   EEEE:星期
   MMMM:月份
   dd:日期
   yyyy:年份
        Date d = new Date();
        SimpleDateFormat sdf 
= new SimpleDateFormat("ss-mm-hh-EEEE-MMMM-dd-yyyy");
        System.
out.println(sdf.format(d));

运行结果
58-21-11-星期五-七月-22-2005

2.DateFormat自带格式
        Date date = new Date(); 

        DateFormat shortDateFormat 
= DateFormat.getDateTimeInstance( DateFormat.SHORT, 
                                                                                                                 DateFormat.SHORT); 
           System.out.println(shortDateFormat.format(date));
           //输出结果      05-7-22 下午11:47


           DateFormat mediumDateFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM,
                                                                                                                      DateFormat.MEDIUM); 
           System.out.println (mediumDateFormat.format(date));
           //输出结果       2005-7-22 23:48:11


           DateFormat longDateFormat = DateFormat.getDateTimeInstance( DateFormat.LONG, 
                                                                                                                DateFormat.LONG);
           System.out.println(longDateFormat.format(date));
           //输出结果      2005年7月22日 下午11时48分45秒


           DateFormat fullDateFormat = DateFormat.getDateTimeInstance( DateFormat.FULL,
                                                                                                               DateFormat.FULL);
           System.out.println (fullDateFormat.format(date));
           //输出结果      Saturday, September 29, 2001 8:44:45 PM EDT

posted on 2005-08-05 23:31 丑男 阅读(414) 评论(0)  编辑  收藏 所属分类: Java


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


网站导航: