aspose file tools*
The moose likes Java in General and the fly likes Java Data and time pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Data and time pattern" Watch "Java Data and time pattern" New topic
Author

Java Data and time pattern

Suman Mummaneni
Ranch Hand

Joined: Dec 14, 2004
Posts: 87
Hello guy,
I have a problem with Java date and time. I am using the locale to format the date and time. I am using SimpleDateFormat for formatting the date. In windows the date formate is set as mm/dd/yyyy but in my program it show up as mm/dd/yy its loosing the last two digits in the year format. I do not understand why this is happenning.
--
Thanks in advance.
Suman Mummaneni
Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
Maybe you could paste some of the code you are using?


Entia non sunt multiplicanda praeter necessitatem
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
I tried the following

SimpleDateFormat fmt=new SimpleDateFormat("MM/dd/yyyy",Locale.US);
Date currDate=new Date(System.currentTimeMillis());
System.out.println(fmt.format(currDate));


and got the expected output (as of today) which is 12/11/2006.

Can you post your code ?


http://www.skillassert.com


Suman Mummaneni
Ranch Hand

Joined: Dec 14, 2004
Posts: 87
Hi,
Here is my code, this is a small utility method that is supposed to return the current date & time string in the same format as the current system locale specifies.



The output I get is "12/12/06 9:55:21 AM" but my Windows regional settings the short date format is specified as "mm/dd/yyyy" but as you can see in the result it is only giving me a two year digit value not a 4 year digit value as my system locale specifies.
Suman Mummaneni
Ranch Hand

Joined: Dec 14, 2004
Posts: 87
Hi,
Here is my code, this is a small utility method that is supposed to return the current date & time string in the same format as the current system locale specifies.



The output I get is "12/12/06 9:55:21 AM" but my Windows regional settings the short date format is specified as "mm/dd/yyyy" but as you can see in the result it is only giving me a two year digit value not a 4 year digit value as my system locale specifies.
Suman Mummaneni
Ranch Hand

Joined: Dec 14, 2004
Posts: 87
Hello guys,
I found the solution for this. The same issue was also posted Sun Java forms
here is the link if your interestedJava Forums
Its a simple logic to convert the pattern into a localized pattern using the SimpleDateFormat class here is the logic

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Data and time pattern