Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GMT to EDT

 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my Java code, I am getting Time in GMT

Date recDateObj = getGMTDate();

Can you please let me know how I can convert this time to one in EDT time zone.



 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anjali S Sharma wrote:In my Java code, I am getting Time in GMT

Date recDateObj = getGMTDate();

Can you please let me know how I can convert this time to one in EDT time zone.





java.util.Date object have no explicit time zone. They have an implicit time zone of UTC since they hold only the number of milliseconds since 1/1/1970 UTC (the epoch). All date helper classes such as SimpleDateFormat assume this epoch and calculate accordingly..

If you need a String representation of the date then you should use SimpleDateFormat and initialise it with the desired time zone.

 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaDatesFaq has some hints on how to work with timezones.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic