Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read the Date Format String specified in control panel

 
Prashant Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the java.util.Locale class and how you can use it with java.text.DateFormat.
 
Prashant Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prashant Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic