• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying Current London time  RSS feed

 
solomon alexander
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!