This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Date formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date formatting" Watch "Date formatting" New topic

Date formatting

Aaron John
Ranch Hand

Joined: May 30, 2005
Posts: 74
I found the following code in the FAQs. I'd like to know how the date format can change depending on the locale, and without hardcoding the formatString, e.g. in the States, the general date format is MM-dd-yyyy (month first then date), while in the Australia the general date format is dd-MM-yyyy (date first then month).

Nicole Lacoste
Ranch Hand

Joined: Oct 04, 2006
Posts: 30

You might want to try looking at the java.text.DateFormat
class. It has a method

Gets the date formatter with the given formatting style for the given locale.

Then you call format(Date) on the DateFormat object that this returns. You can use a DateFormat to read or write dates in a particular format. Have a look at the doc.

It is sorta covered in the JavaRanch Style Guide.
subject: Date formatting
Similar Threads
String to date format
Code review required for converting dateformat
String date in to Date type
how to convert date to a string
xsd datetime format