Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Data and time pattern

 
Suman Mummaneni
Ranch Hand
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could paste some of the code you are using?
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Suman Mummaneni
Ranch Hand
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic