• 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

Displaying Current London time

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I tried the following to display the current London Time:

TimeZone tz = TimeZone.getTimeZone("Europe/London");

System.out.println("Current London Time:"+Calendar.getInstance(tz).getTime());

However, this code always shows my local time
Any thoughts will be really appreciated?

Thanks
Alex
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that getTime() returns a Date, and the toString() method of Date always uses your computer's default time zone and format, i.e. local time. There's nothing wrong with getTime() returning a Date, that's fine - you just need to know that the toString() method will not handle time zones for you. Instead, you can do this with a DateFormat object, e.g.
reply
    Bookmark Topic Watch Topic
  • New Topic