Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get system date format in java

 
Devika Chandran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my java application i want to change all date according to the date format available in system..that is as per user given... how to get the system date format( format of date shown on taskbar)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch. The class java.util.DateFormat has a number of static factory methods for getting DateFormat objects that use the default locale.

For example, DateFormat.getDateTimeInstance(). It will give you a DateFormat object that you can use to format the date and time according to the language settings of the operating system.
 
Devika Chandran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I knw about DateFormat. But i want to know how to get the format of date like dd/MM/yyyy or dd-MM-yyy.....
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The javadocs of the SimpleDateFormat class have the details on that.
 
Devika Chandran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kkkk thank you
 
Devika Chandran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried.but am getting same format all the time even i change the format at calendar settings in system
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, you're expecting the Windows setting to have an impact on the default JVM date format? I don't think it does. See http://stackoverflow.com/questions/6711925/how-can-i-so-date-and-time-formatting-in-java-that-respects-the-users-os-settin about how to use the Windows Registry to get the information you'd need for formatting.
 
Winston Gutkowski
Bartender
Pie
Posts: 10504
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:See [link] about how to use the Windows Registry to get the information you'd need for formatting.

Ugh. The Windows registry is bad enough without having to try to plough through it in Java.

@Devika: Is there some reason why this is so important to you? Major stuff like language will be gleaned from system settings, but trawling things like registries simply in order to replicate a date format exactly is really going to impact the platform-independence of your app.

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic