• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert New York timezone to UK timezone

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic