Reference class:
Java. Text
Dateformat
java.lang.Object java.text.Format java.text.DateFormat
-
All Implemented interfaces:
-
Serializable, cloneable
-
Directly known subclass:
-
Simpledateformat
Constructor Summary |
protected |
DateFormat() Create a new dateformat. |
Letter |
Date or time element |
Indicates |
Example |
G |
Era identifier |
Text |
AD |
y |
Year |
Year |
1996 ;96 |
M |
Month in Year |
Month |
July ;Jul ;07 |
w |
Week in Year |
Number |
27 |
W |
The number of weeks in the month |
Number |
2 |
D |
Days in years |
Number |
189 |
d |
Days in a month |
Number |
10 |
F |
Week in the month |
Number |
2 |
E |
Days in a week |
Text |
Tuesday ;Tue |
a |
AM/PM mark |
Text |
PM |
H |
Hours in a day (0-23) |
Number |
0 |
k |
Hours per day (1-24) |
Number |
24 |
K |
Hours in AM/PM (0-11) |
Number |
0 |
h |
Hours in AM/PM (1-12) |
Number |
12 |
m |
Minutes in an hour |
Number |
30 |
s |
Seconds in minutes |
Number |
55 |
S |
Milliseconds |
Number |
978 |
z |
Time Zone |
General Time Zone |
Pacific Standard Time ;PST ;GMT-08:00 |
Z |
Time Zone |
RFC 822 Time Zone |
-0800 |
Date and Time Modes |
Result |
"yyyy.MM.dd G 'at' HH:mm:ss z" |
2001.07.04 AD at 12:08:56 PDT |
"EEE, MMM d, ''yy" |
Wed, Jul 4, '01 |
"h:mm a" |
12:08 PM |
"hh 'o''clock' a, zzzz" |
12 o'clock PM, Pacific Daylight Time |
"K:mm a, z" |
0:08 PM, PDT |
"yyyyy.MMMMM.dd GGG hh:mm aaa" |
02001.July.04 AD 12:08 PM |
"EEE, d MMM yyyy HH:mm:ss Z" |
Wed, 4 Jul 2001 12:08:56 -0700 |
"yyMMddHHmmssZ" |
010704120856-0700 |
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" |
2001-07-04T12:08:56.235-0700 |
String |
format(Date date) Format a date as a date/time string. |
Date |
parse(String source) Analyzes text from the beginning of a given string to generate a date |
Public static void main (string [] ARGs) throws parseexception ...{
// String convert to date according the Format String
Date = new date ();
Simpledateformat strtodate = new simpledateformat ("yyyy-mm-dd-hh: mm: SS ");
// Parse format string to date
Date = strtodate. parse ("2000-12-11-06:23:12 ");
System. Out. println (date );
// Date convert to format string according the Format String
Simpledateformat datetostr = new simpledateformat ("dd/mm/yyyy-hh: mm: SS ");
// Parse date to Format String
String temp = datetostr. Format (date );
System. Out. println (temp );
}
Mon Dec 11 06:23:12 GMT 2000
11/12/2000-06:23:12