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 pattern for DateFormat 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 pattern for DateFormat" Watch "date pattern for DateFormat" New topic

date pattern for DateFormat

Mette Russell

Joined: May 07, 2008
Posts: 11
I'm working on an application that has been upgraded from Websphere 5.1 to 6.1, and everything looks fine except the showing of dates.
Including in the Websphere update is also a change in the used JDK - from 1.4 to 1.5 (or 5.0).

The dates used to be shown in the the pattern "dd-MM-yyyy", but after the upgrade, they are shown as "yyyy-MM-dd".

Can anybody tell me why this have happened?

The default Locale has been set to "da_DK".
Can anybody tell me where the "definition" of the different Locales can be found?

Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Would you happen to be using Solaris? I had a cron job that had a screwed up locale. Setting the following environment variables set the locale correctly (US locale, of course):

An alternative is to use SimpleDateFormat to format a Date in a particular way
Another alternative is to pass a Locale instance in to the format() method of DateFormat.

[How To Ask Questions On JavaRanch]
Mette Russell

Joined: May 07, 2008
Posts: 11
No, I'm not using Solaris. I'm currently testing on Windows.

I have already changed the code to use SimpleDateFormat, but I'm curious and puzzled about what triggered the change from pattern "dd-MM-yyyy" to "yyyy-MM-dd".

I'm guessing it is because of the upgrade from jdk 1.4 to 5.0 - but I have found no proof of this.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

It's very hard to tell, because we haven't seen your code, so we don't know how you were putting those dates on screen before you made the change. Were you just using toString() on java.util.Date objects?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
arulk pillai
Ranch Hand

Joined: May 31, 2007
Posts: 3371
Did you check your regional settings under control panel in windows?

[] | [Java job hunting know how] | [Java resumes]
Mette Russell

Joined: May 07, 2008
Posts: 11
Hi Jesper

It shouldn't really matter what the code looks like. I was expecting my code to work exactly the same way before and after the upgrade from Websphere 5.1 to 6.1 (and jdk 1.4 to 1.5) - but it didn't!
Note that nothing was changed during the upgrade. The code, data base and property files were exactly the same.

The code used DateFormat.getDateInstance() and the default Locale was set to da_DK.
While debugging (in WAS 6.1), I found the date pattern stored for DateFormat was 'yyyy-MM-dd', and thus this was the format of the parsed dates.
My theori is that this date pattern definition must have changed from jdk 1.4 to 1.5, but I can't find any documentation on this.
I suppose it could be a change in the Locale definition for da_DK, but I don't know where to find these definitions.
Mette Russell

Joined: May 07, 2008
Posts: 11
Hi Arulk

My settings have been set to use the danish settings - which is dd-mm-yyyy.
I agree. Here's the link:
subject: date pattern for DateFormat
jQuery in Action, 3rd edition