×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Time Zone Conversion
 

Submitted by: Octavia Anghel(octaviaanghel@gmail.com)

Tuesday Feb 6th 2018 by Octavia Anghel

Language: Java, Expertise: Beginner - Learn how to avoid this common time zone conversion mistake.

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();
}
Home
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved