Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
Feb 6, 2018

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Time Zone Conversion

The method below does nothing because the returned Date is exactly the same with the input value.

Always remember that the Date does not carry time zone information, it is always UTC, and the set and get methods convert between UTC and the actual time zone of the Calendar.

public static Date convertTimeZone(Date date, TimeZone timezone) {
   Calendar cal = Calendar.getInstance();
   cal.setTimeZone(TimeZone.getTimeZone("UTC"));
   cal.setTime(date);
   cal.setTimeZone(timezone);
   return cal.getTime();
}
Octavia Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date