aspose file tools*
The moose likes Java in General and the fly likes Date Format Quickie 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 Format Quickie" Watch "Date Format Quickie" New topic
Author

Date Format Quickie

Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
Hi I'm working on a system where the user wants to see dates as

DD:MM:YYYY

As there isn't a default pattern for this in DateFormat class I did the following


I've noticed that with an American US Locale 9th of April 2006 is shown as
09:04:2006 as per the pattern.

This is true to the pattern I asked for but "wrong" for US users. I wonder if there is a concise way for me to both format dates as DD:MM:YYYY AND also MM D:YYYY dependent on the Locale? e.g in UK its 09:04:2006 and 04:09:2006 in U.S ?

TIA Graham
Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
couldn't you use the value of getCurrentLocale() to determine the format of the date. summat like
[code]
String format = null;
if(getCurrentLocale().equals("whatever US locale String looks like"))
{
format="MM.dd.yyyy";
}
else
{
format = "dd.MM.yyyy";
}

and then use the String 'format' when initialising the DateFormat class?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

When you have a requirement that leads you into basic questions that don't have good answers (that's the case with your post) then that means the requirement was a bad idea.

I find that the ISO format "YYYY-MM-DD" works perfectly well for US users, and I expect it would be equally acceptable to users all over the world. It's obvious that the month comes before the day when you do it that way. So I would recommend you try that.
Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
Hi Paul

I find that the ISO format "YYYY-MM-DD" works perfectly well for US users, and I expect it would be equally acceptable to users all over the world

not so sure Europeans would like it much - I'm unwilling to accept I'm in a minority of one!


Cheers
As
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
One way of doing it is having the dateformat string as a property in a resource bundle.
That way you can configure it for each locale, with a minimum of fuss.

However you do have to retrieve it from the bundle anytime you want to format a date...
[ July 17, 2006: Message edited by: Stefan Evans ]
Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
Thanks for the replies chaps, Stefan I like your suggestion and will try that.

I find that the ISO format "YYYY-MM-DD" works perfectly well for US users, and I expect it would be equally acceptable to users all over the world.


I know what your saying Paul but this assumes I control/have a say in what the customer wants and I'm afraid my customer is a large mega-corp that makes cars and whatever they say goes no questions asked even if its illogical
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date Format Quickie