Localization of date time, custom format
Localization can also be localized
Import java.util. *;
Import java.text. *;
Public class fdate {
Public static void main (String [] args) {
// Initialize a localized object
Locale Currentlocale = New Locale ("fr" / * language * /, "fr" / * country * /);
// Create a DateFormat object
// DataFormat has the following formats, this example uses default
// Default 10-APR-98
// short 4/10/98
// Medium 10-APR-98
// long April 10, 1998
// Full Friday, April 10, 1998
DateFormat Dateformatter = DateFormat.getdateTimeInstance (DateFormat.default, // Date
DateFormat.full, // Time
Currentlocale);
// Current date object
Date Today = new date ();
// Show current date
System.out.println (Dateformatter.Format (Today));
}
}
The output is:
17 oct. 2004 17 h 10 CST
Of course, you can also customize the display mode.
Import java.util. *;
Import java.text. *;
Public class custom {
Public static void main (String [] args) {
// Initialize a localized object
Locale Currentlocale = New Locale ("CH" / * language * /, "cn" / * country * /);
Date Today;
SimpleDateFormat Formatter;
// Set the display format
Formatter = New SimpleDateFormat ("YYYY M Monthly D-day E A HH Point MM Sizse SS q", Currentlocale);
Today = new date ();
System.out.println (Formatter.Format (Today));
}
}
The display result is:
Sunday, October 31, 2004, 05:33, 37 seconds CST
SimpleDateFormat is here introduced here http://java.sun.com/j2se/1.4.2/docs/api/java/text/simpledateformat.html