• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting timezone

 
Srikanth Madasu
Ranch Hand
Posts: 48
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What line is the error from?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On which line do you get the exception?

You can use DateFormat/SimpleDateFormat to parse a String to a Date.
 
Srikanth Madasu
Ranch Hand
Posts: 48
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error is on line 30 where I format the obj...

d.format(c);

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use DateFormat.format() with a Calender instance. You need to use:
 
Srikanth Madasu
Ranch Hand
Posts: 48
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked.. Thanks much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic