First look at all the representations of the formatted log.
[Plain]View plain copy
- Time Date Identifier:
- YYYY: Year
- MM: Month
- DD: Day
- HH:1~12-hour System (1-12)
[Plain]View plain copy
- HH:24-hour System (0-23)
- MM: Min
- SS: Seconds
- S: MS
- E: Day of the week
- D: The day ordinal of a year
- F: The first few weeks of January (the total number of days in this month divided by 7)
- W: The first few weeks of the year
- W: The week of January (will be calculated according to the actual situation)
- A: Last afternoon logo
- K: Similar to HH, indicating a 24-hour day (1-24).
- K: And Hh<span > Almost </span><span, which represents a 12-hour day (0-11). </span>
- Z: Indicates time zone
Be aware of the size of the case, or it will be formatted after the date will be very messy Oh!!!
At the same time not a letter can be written more than, such as: yyyyyyyyyyy. According to your number size, according to the length of the letter written, in front of the 0.
For example: you want to put 2013-08-13 15:29:44 this time format to August 13, 2013 15:29 44 seconds
Accidentally mistake the case in the time identifier in the formatted date.
[Java]View plain copy
- SimpleDateFormat SDF = new SimpleDateFormat ("yyyy mm month dd Day hh mm min ss sec");
- It's written like this. The final result is wrong.
[Java]View plain copy
- 2013 August 14th 15 o'clock 08 minutes 59 seconds
[Java]View plain copy
- This mm is written here is the month of the expression. And the minute is the expression of mm. So pay attention to,
The following is the most complete example of a date format word.
[Java]View plain copy
- SimpleDateFormat SDF = new SimpleDateFormat ("Yyyyyyyy-mm-dd hh (hh): Mm:ss S E D F w w a k K z");
- Long times = System.currenttimemillis ();
- System.out.println (times);
- Date date = new Date (times);
- String Tim = Sdf.format (date);
- System.out.println (Tim);
Results of the output:
[HTML]View plain copy
- 00002013-08-14 15 (03): 56:40 742 weeks 3,226 2 33 3 pm 3 CST
[Java]View plain copy
- SimpleDateFormat SDF = new SimpleDateFormat ("Now is the yyyy mm month DD Day hh (HH) mm Sub SS s millisecond Week E this year D Day this month the first F week this year the first W star Period of the month of the first W week of today's a k1~24 system time k0-11 hours time Z time zone ");
- Long times = System.currenttimemillis ();
- System.out.println (times);
- Date date = new Date (times);
- String Tim = Sdf.format (date);
- System.out.println (Tim);
Output Result:
[HTML]View plain copy
- Now is August 14, 2013 16 (04) when 03 minutes 03 seconds 812 milliseconds Week Wednesday this year the No. 226 day this month 2nd week this year 33rd week this month 3rd week today's afternoon 161~24 system time 40-11 hour time CST Area
Identifier table:
Symbol |
meaning |
Presentation |
Example |
G |
ERA designator |
Text |
AD |
Y |
Year |
Number |
2009 |
M |
Month in year |
Text & Number |
July & 07 |
D |
Day in month |
Number |
10 |
H |
Hour in am/pm (1-12) |
Number |
12 |
H |
Hour in Day (0-23) |
Number |
0 |
M |
Minute in hour |
Number |
30 |
S |
Second in minute |
Number |
55 |
S |
Millisecond |
Number |
978 |
E |
Day in Week |
Text |
Tuesday |
D |
Day in year |
Number |
189 |
F |
Day's week in month |
Number |
2 (2nd Wed in July) |
W |
Week in year |
Number |
27 |
W |
Week in month |
Number |
2 |
A |
AM/PM Marker |
Text |
Pm |
K |
Hour in Day (1-24) |
Number |
24 |
K |
Hour in am/pm (0-11) |
Number |
0 |
Z |
Time zone |
Text |
Pacific Standard Time |
‘ |
Escape for text |
Delimiter |
(none) |
‘ |
Single quote |
Literal |
‘ |
Text turn: http://blog.csdn.net/yangbobo1992/article/details/9965105
Java uses SimpleDateFormat to format date time. Rp