查看完整版本: [-- SimpleDateFormat的用法 --]

风信Java论坛 ›› Java 基础开发 ›› SimpleDateFormat的用法 登录 -> 注册

1F SimpleDateFormat的用法   唧唧 Post by : 2008-07-11 00:51:04.0

G 年代标志符
y 年
M 月
d 日
h 时 在上午或下午 (1~12)
H 时 在一天中 (0~23)
m 分
s 秒
S 毫秒
E 星期
D 一年中的第几天
F 一月中第几个星期几
w 一年中第几个星期
W 一月中第几个星期
a 上午 / 下午 标记符
k 时 在一天中 (1~24)
K 时 在上午或下午 (0~11)
z 时区

java代码
  1. package org.javawind.beans;  
  2.  
  3. import java.text.*;  
  4. import java.util.Date;  
  5.  
  6. public class fmt {  
  7.     public static void main(String[] args) {  
  8.         SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");  
  9.         SimpleDateFormat myFmt1=new SimpleDateFormat("yy/MM/dd HH:mm");    
  10.         SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
  11.         SimpleDateFormat myFmt3=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");  
  12.         SimpleDateFormat myFmt4=new SimpleDateFormat("一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");  
  13.  
  14.         Date now=new Date();  
  15.         System.out.println(myFmt.format(now));  
  16.         System.out.println(myFmt1.format(now));  
  17.         System.out.println(myFmt2.format(now));  
  18.         System.out.println(myFmt3.format(now));  
  19.         System.out.println(myFmt4.format(now));  
  20.           
  21.         System.out.println(now.toString());  
  22.     }  

执行结果:

2008年07月11日 00时50分17秒
08/07/11 00:50
2008-07-11 00:50:17
2008年07月11日 00时50分17秒 星期五
一年中的第 193 天 一年中第28个星期 一月中第2个星期 在一天中24时 CST时区
Fri Jul 11 00:50:17 CST 2008


风信Java论坛 ›› Java 基础开发 ›› SimpleDateFormat的用法 登录 -> 注册

查看完整版本: [-- SimpleDateFormat的用法 --]
CopyRight © 2008-2009 JavaWind.Net Studio All Rights Reserved
Powered By JWind.BBS Vesion 1.0.0 Beta1 Processed in 6 ms,0 (Queries)  Gzip enabled
粤ICP备07511478号