Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Convert New York timezone to UK timezone

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?
Java Cowboy
Posts: 16084
Android Scala IntelliJ IDE Spring Java
  • 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.
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?

It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic