aspose file tools*
The moose likes Java in General and the fly likes Read the Date Format String specified in control panel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Read the Date Format String specified in control panel" Watch "Read the Date Format String specified in control panel" New topic
Author

Read the Date Format String specified in control panel

Prashant Gupta
Greenhorn

Joined: Sep 16, 2005
Posts: 4
I want to read the date format string (i.e. yyyy.MM.dd) specified via Windows ( Control Panel->Regional options)from the java code.

Can someone tell me how to read that.?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Look at the java.util.Locale class and how you can use it with java.text.DateFormat.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Prashant Gupta
Greenhorn

Joined: Sep 16, 2005
Posts: 4
Tried that..but Locale class does not expose any method to get the Date Format String..it has getCountry(),getDisplayCountry(),getDisplayVariant()..but nothing specific or close to System level date settings.
Santosh Maskar
Ranch Hand

Joined: Jul 02, 2003
Posts: 226
Try this one

public String calToStr(Calendar cal) throws Exception
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
//You can use Date format as per your requrirment : yyyy-MM-dd

String dateString = formatter.format(cal.getTime());
return dateString;
}

Thanks,
Santosh

[ September 16, 2005: Message edited by: Santosh Maskar ]
[ September 16, 2005: Message edited by: Santosh Maskar ]
Prashant Gupta
Greenhorn

Joined: Sep 16, 2005
Posts: 4
yea...but as per my requirements I need to get the format String from the System.I don't want to specify any format String in the code or in property file.

I want to read the the Dtae Format String from the Control settings ->reginol settings.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
In that case, use the DateFormat.getDateInstance(int) method. Using different parameters, you can get the date as defined on your system in short, medium or long format.


Ping & DNS - my free Android networking tools app
Prashant Gupta
Greenhorn

Joined: Sep 16, 2005
Posts: 4
Thanks guys...but I think there is a bug with jdk1.4 that is why I am not getting expected output..

chcek out this link:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4514389
 
Don't get me started about those stupid light bulbs.
 
subject: Read the Date Format String specified in control panel