• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

DateTime conversion Issue

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the DateTime in the following format.
2013-08-08T04:23:17-07:00

How to convert the above Date into the format like 05/28/2013 10:52:36 PM


Can anyone help on this.


Thanks in advance.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the SimpleDateFormat class
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stuart A. Burkett wrote:Use the SimpleDateFormat class


@sanjay: And don't use that format for anything except display.

The format you've received is ISO 8601 which, while not very pretty to look at, is an internationally recognised standard that works anywhere in the world.

Yours, OTOH, is a CLOCK time; and it will only work for display.

So: if you're putting it into any files - especially ones that get sent anywhere - use the format you were given.

Winston
 
sanjay kams
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the input.
This is the code that I am trying to get the PST timezone for the given Input.
In the below code, PST String doesn't give the required value(i.e., expecting to get the result like this "8/8/2013 5:40:12 AM"). I think, I did something wrong in the code. Can anyone find and show me the right way.


Thanks in Advance.
 
sanjay kams
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also I am getting error for the line "String PST = df.format(Date);" as

java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:301)
at java.text.Format.format(Format.java:157)


How to avoid this error. I different in different ways. But can't remove the error. Please help me on this.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The format method takes an object of type Date, you are passing in a String.
You need to convert your initial string to a Date object and then format it to the output string you want.
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ALso, follow Java conventions. All variable names should start with lowercase. So Date is a very very bad variable name. No only because it doesn't follow convention, but it is easily confused with the Date class. Choose better variable names.
 
Ranch Hand
Posts: 51
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess this is what you want to use:
 
reply
    Bookmark Topic Watch Topic
  • New Topic