• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Java Data and time pattern

 
Ranch Hand
Posts: 99
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you could paste some of the code you are using?
 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 99
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 99
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 99
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic