spring - Java Date format -
I have a spring web application that runs in Tomcat, I set the date and number format for a specific format in my application. Have to do.
Can I set any descriptor in the form specific to my application or can I set all the system formats only?
I want to use this method: yyyy.mm.dd.
This code is incorrect because it is not a standard locale pattern:
String CurrentDate = Simple Data Format.GetDateTimeInstance (Dataformat.Hart, Dateformat.Hart, Locale.UK ). Format (new date ());
But I do not want to type the pattern everywhere in the application, I want to set the pattern once.
I would like to if I type this code:
string current = simple data format.gatedate instance (date format.html). Format (new date ());
The result is: 2010.08.04.
Is this possible?
java.util.Date
objects do not have a format (they Only represent the date and time values, such as integers that represent only one number value and know something about the formatting numbers of 't').
There is no system-wide default date format setting. When you print the date
object (by implicit or explicitly) by calling toString ()
, it will be printed with a fixed, default format that you can change Can not:
System.out.println (new date ()); // Example Output: Wed Aug 04 09:46:57 CEST 2010
If you want to show a date with a specific format, then java.text.DateFormat
to format the object. For example:
date format df = new simple data format ("DD-MM-yyyy HH: mm: ss"); System.out.println (df.format (new date ())); // Example output: 04-08-2010 09:48:47
Comments
Post a Comment