This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 11161
    
  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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting timezone
 
Similar Threads
Calendar
Expressiveness using implicit conversions
Possble Calendar bug with daylight saving time
Wrong Hour/Timezone
Tomorrows date