标签:lin .net 日历 javase java ee 显示 pattern post 文章
版权声明:本文为博主原创文章,未经博主允许不得转载。
Java Calendar 类时间操作,这也许是创建日历和管理最简单的一个方案,示范代码很简单。
演示了获取时间,日期时间的累加和累减,以及比较。
原文地址:blog.csdn.NET/joyous/article/details/9630893
Calendar 的 month 从 0 开始,也就是全年 12 个月由 0 ~ 11 进行表示。
Calendar.SUNDAY = 1
Calendar.MONDAY = 2
Calendar.TUESDAY = 3
Calendar.WEDNESDAY = 4
Calendar.THURSDAY = 5
Calendar.FRIDAY = 6
Calendar.SATURDAY = 7
SimpleDateFormat 的格式定义
Letter | Date or Time Component | Presentation | Examples |
---|---|---|---|
G |
Era designator | Text | AD |
y |
Year | Year | 1996 ; 96 |
Y |
Week year | Year | 2009 ; 09 |
M |
Month in year (context sensitive) | Month | July ; Jul ; 07 |
L |
Month in year (standalone form) | Month | July ; Jul ; 07 |
w |
Week in year | Number | 27 |
W |
Week in month | Number | 2 |
D |
Day in year | Number | 189 |
d |
Day in month | Number | 10 |
F |
Day of week in month | Number | 2 |
E |
Day name in week | Text | Tuesday ; Tue |
u |
Day number of week (1 = Monday, ..., 7 = Sunday) | Number | 1 |
a |
Am/pm marker | Text | PM |
H |
Hour in day (0-23) | Number | 0 |
k |
Hour in day (1-24) | Number | 24 |
K |
Hour in am/pm (0-11) | Number | 0 |
h |
Hour in am/pm (1-12) | Number | 12 |
m |
Minute in hour | Number | 30 |
s |
Second in minute | Number | 55 |
S |
Millisecond | Number | 978 |
z |
Time zone | General time zone | Pacific Standard Time ; PST ; GMT-08:00 |
Z |
Time zone | RFC 822 time zone | -0800 |
X |
Time zone | ISO 8601 time zone | -08 ; -0800 ; -08:00 |
Java Calendar 演示代码如下:
要计算时间差,可用 Calendar.getTimeInMillis() 取得两个时间的微秒级的时间差,再加以换算即可,比如获得相差天数,代码如下:
标签:lin .net 日历 javase java ee 显示 pattern post 文章
原文地址:http://www.cnblogs.com/aipan/p/6102588.html