• 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Convert New York timezone to UK timezone  RSS feed

 
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
88
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.
 
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
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!