• 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

Get date and time using TimeZone.

 
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

Can I get the perfect date and time at a perticular location with the help of TimeZone?

The code I am using is:



The output is:
Eastern Standard Time
-18000000
EST
Date:Sun Dec 26 13:34:51 IST 2010
Press any key to continue . . .

I am trying to get the date and time at the specified TimeZone (Eastern Standard Time) but I am getting the system date and time.
Am I making any mistake in the code? Please guide me.

Thanks and regards,
Nitin.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Three-letter time zone IDs are deprecated, therefore you are better of by using the long zone id - eg. "America/Los_Angeles".

The TimeZone isn't been shown on a Date object, because it has no information on it - but it is stored on the Calendar object, therefore you need to use this information when you want to show the correct Date/Time by using SimpleDateFormat.

 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic