• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert New York timezone to UK timezone  RSS feed

 
Joe Cheung
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My application is running on machines located in NY. How can I convert the current time to UK TZ? Anyone give me the code?

By the way, anyone has the list of "ID for all countries" which we use to specify timezone in setTimeZone?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Date object in Java does not have a timezone. It represents a specific point in time, regardless of the timezone. Timezones come into the story when you want to convert a Date object into a string to display it.

You can use a DateFormat object to convert a Date to a String. On the DateFormat object, you can set the timezone that you want to display the date in. For example:

You can get a list of all available timezone IDs by calling TimeZone.getAvailableIDs() - see the API documentation of class TimeZone.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Country Codes

Language codes

Of course you could just add 5 hours to the EST (NY) time to get the UK time (GMT) (although we in the UK are currently in BST).

This would all of been fine until the US govement decided to change when it applied daylight saving, which is now out of sync, so I dont think this simple "hack" will be very robust.

Perhaps looking at the DateFormat class (as mentioned else where) might help, or the Calendar class (GorgornCalendar? not sure I have spelt that right) and applying a locale of en/GB will help to the Calendar/DateFormatter?

G
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!