GeeCON Prague 2014*
The moose likes Java in General and the fly likes Converting timezone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting timezone" Watch "Converting timezone" New topic
Author

Converting timezone

Srikanth Madasu
Ranch Hand

Joined: Sep 10, 2008
Posts: 48

I have a requirement of converting times in different time zones to PST.

example if I give "03:30 AM CST" my method should return time in PST.



but its throwing following error:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date

Can some one tel me what is mistake? and is htere a better/elegant way of doing this?

Thanks in advance!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11354
    
  16

What line is the error from?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

On which line do you get the exception?

You can use DateFormat/SimpleDateFormat to parse a String to a Date.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Srikanth Madasu
Ranch Hand

Joined: Sep 10, 2008
Posts: 48

Error is on line 30 where I format the obj...

d.format(c);

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You can't use DateFormat.format() with a Calender instance. You need to use:
Srikanth Madasu
Ranch Hand

Joined: Sep 10, 2008
Posts: 48

That worked.. Thanks much!
 
GeeCON Prague 2014
 
subject: Converting timezone