File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.

I agree. Here's the link:
subject: Date formatting
It's not a secret anymore!