用SimpleDateFormat类,格式化日期和时间模式
来源:互联网 发布:swmm软件 编辑:程序博客网 时间:2024/05/16 11:16
定义了以下模式字母(所有其他字符 'A' 到'Z'和 'a' 到'z'都被保留):
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 时区 General time zone Pacific Standard Time; PST; GMT-08:00
Z 时区 RFC 822 time zone -0800
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 时区 General time zone Pacific Standard Time; PST; GMT-08:00
Z 时区 RFC 822 time zone -0800
import java.text.*;
import java.util.Date;
public class FormatDateTime {
public static void main(String[] args) {
/// 打印出2006年11月17日 15时19分56秒
SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
//打印 06/11/17 15:19
SimpleDateFormat myFmt1=new SimpleDateFormat("yy/MM/dd HH:mm");
//2006-11-17 15:19:56
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//2006年11月17日 15时19分56秒 星期五
SimpleDateFormat myFmt3=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");
// 一年中的第 321 天 一年中第46个星期 一月中第3个星期 在一天中15时 CST时区
SimpleDateFormat myFmt4=new SimpleDateFormat(
"一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");
Date now=new Date();
System.out.println(myFmt.format(now));
System.out.println(myFmt1.format(now));
System.out.println(myFmt2.format(now));
System.out.println(myFmt3.format(now));
System.out.println(myFmt4.format(now));
System.out.println(now.toGMTString());// 17 Nov 2006 07:19:56 GMT
System.out.println(now.toLocaleString());// 2006-11-17 15:19:56
System.out.println(now.toString());// Fri Nov 17 15:19:56 CST 2006
}
}
import java.util.Date;
public class FormatDateTime {
public static void main(String[] args) {
/// 打印出2006年11月17日 15时19分56秒
SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
//打印 06/11/17 15:19
SimpleDateFormat myFmt1=new SimpleDateFormat("yy/MM/dd HH:mm");
//2006-11-17 15:19:56
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//2006年11月17日 15时19分56秒 星期五
SimpleDateFormat myFmt3=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");
// 一年中的第 321 天 一年中第46个星期 一月中第3个星期 在一天中15时 CST时区
SimpleDateFormat myFmt4=new SimpleDateFormat(
"一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");
Date now=new Date();
System.out.println(myFmt.format(now));
System.out.println(myFmt1.format(now));
System.out.println(myFmt2.format(now));
System.out.println(myFmt3.format(now));
System.out.println(myFmt4.format(now));
System.out.println(now.toGMTString());// 17 Nov 2006 07:19:56 GMT
System.out.println(now.toLocaleString());// 2006-11-17 15:19:56
System.out.println(now.toString());// Fri Nov 17 15:19:56 CST 2006
}
}
- 用SimpleDateFormat类,格式化日期和时间模式
- 用SimpleDateFormat类,格式化日期和时间模式
- 用SimpleDateFormat格式化日期和时间
- SimpleDateFormat格式化日期时间格式
- 日期格式化类SimpleDateFormat
- 日期格式化和SimpleDateFormat问题
- Java中格式化日期时间的类:SimpleDateFormat 用法详解
- java 使用simpleDateFormat格式化日期 时间
- java 使用simpleDateFormat格式化日期 时间
- java 使用simpleDateFormat格式化日期 时间
- 使用 SimpleDateFormat 类格式化日期
- Java日期格式化类SimpleDateFormat
- Java格式化日期类DateFormat和SimpleDateFormat的学习
- 使用 SimpleDateFormat 格式化日期和使用printf格式化日期
- 使用Date和SimpleDateFormat格式化时间
- SimpleDateFormat 使用方法和中英文时间格式化转换
- SimpleDateFormat格式化日期
- SimpleDateFormat格式化日期
- Servlet技术及其与CGI的比较
- rails mapping
- Shmily
- oracle10g错误信息(ORA-12500 to ORA-12699 )
- 搜索技术总结整理
- 用SimpleDateFormat类,格式化日期和时间模式
- Win2003下Asp配置技巧 http 500内部服务器错误
- Oracle前置更新触发器
- 类初始化
- 中文搜索引擎之文本分类
- Oracle中如何删除表中重复数据
- test
- oracle10g错误信息(ORA-12700~ORA-19361 )
- 瘦P被LP拿去当MP4玩,好在获得NDSL购入许可