This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to get system date format in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get system date format in java" Watch "How to get system date format in java" New topic
Author

How to get system date format in java

Devika Chandran
Greenhorn

Joined: Feb 13, 2014
Posts: 4
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

Joined: Aug 16, 2005
Posts: 13884
    
  10

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Devika Chandran
Greenhorn

Joined: Feb 13, 2014
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
The javadocs of the SimpleDateFormat class have the details on that.


Ping & DNS - updated with new look and Ping home screen widget
Devika Chandran
Greenhorn

Joined: Feb 13, 2014
Posts: 4
kkkk thank you
Devika Chandran
Greenhorn

Joined: Feb 13, 2014
Posts: 4
I tried.but am getting same format all the time even i change the format at calendar settings in system
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
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

Joined: Mar 17, 2011
Posts: 7081
    
  16

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

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get system date format in java
 
Similar Threads
Date Question
how do i get system date in java http servlets
Date format
How to get Date Format of a System??
How to display system date?