Reference class: java.text
Class DateFormat
Java.lang.Object
java.text.Format
java.text.DateFormat
all implemented interfaces:Serializable, cloneable
child classes are directly known:SimpleDateFormat
Letters |
date or time element |
represents |
Sample |
G |
Era Marker |
Text |
AD |
Y |
Years |
Year |
1996; 96 |
M |
Months of the year |
Month |
July; June June; 07 |
W |
Number of weeks in the year |
Number |
27 |
W |
Number of weeks in the month |
Number |
2 |
D |
Days in the year |
Number |
189 |
D |
Days in the month |
Number |
10 |
F |
Weeks in the month |
Number |
2 |
E |
Days in the week |
Text |
Tuesday; Tue |
A |
AM/PM Mark |
Text |
Pm |
H |
Number of hours in a day (0-23) |
Number |
0 |
K |
Number of hours in a day (1-24) |
Number |
24 |
K |
Number of hours in am/pm (0-11) |
Number |
0 |
H |
Number of hours in am/pm (1-12) |
Number |
12 |
M |
Number of minutes in the hour |
Number |
30 |
S |
Number of seconds in minutes |
Number |
55 |
S |
Number of milliseconds |
Number |
978 |
Z |
Time |
General Time Zone |
Pacific Standard time; PST; gmt-08:00 |
Z |
Time |
RFC 822 Time Zone |
-0800 |
date and time patterns |
Results |
"YYYY. Mm.dd G ' at ' HH:mm:ss z ' |
2001.07.04 AD at 12:08:56 PDT |
"EEE, MMM D, ' yy" |
Wed, April 4, ' 01 |
"H:mm a" |
12:08 PM |
"HH ' o ' clock ' A, zzzz" |
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 June 2001 12:08:56-0700 |
"Yymmddhhmmssz" |
010704120856-0700 |
"Yyyy-mm-dd ' T ' HH:mm:ss." Sssz " |
2001-07-04t12:08:56.235-0700 |
public static void Main (string[] args) throws parseexception ... {
The string convert to date according the format string
Date 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);
The 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 06:23:12 GMT 2000
11/12/2000-06:23:12