• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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.

 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic