File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "date pattern for DateFormat" Watch "date pattern for DateFormat" New topic
Author

date pattern for DateFormat

Mette Russell
Greenhorn

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?

Thanks.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Mette Russell
Greenhorn

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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
arulk pillai
Author
Ranch Hand

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


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Mette Russell
Greenhorn

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: date pattern for DateFormat
 
Similar Threads
JSTL <fmt:parseDate>
Convert Java.sql.Date to String or Java.util.Date
Date conversion to String- urgent help!
Date Format ,Please help!
convert date to dd-mm-yyyy pattern