I'm looking for code that converts date/time in GMT format to the local time zone format. I found some examples on the web, but they don't account for daylight savings. Is there any java function that would do that for me?
Do you mean that you want to convert a UTC Date/Time in a Local Date/Time? Assuming that your Java program runs in local time (you can enforce that with the java runtime parameter -Duser.timezone).
long utcMiliseconds = utcDate.getTime();
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(utcMiliseconds);
Date localTime = new Date(utcMiliseconds + cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET));
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.