Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Read the Date Format String specified in control panel

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic