0

Here is my code to do this. My question is how does android(any other system take care of DST internally). DST rules can change. Or is it a too corner case to be of any real concern.

public long getLocalTimeFromUTCTime(long utcTime)
{
    Time time = new Time();
    time.set(utcTime);
    TimeZone localTimezone = TimeZone.getDefault();
    time.switchTimezone(localTimezone.getID());
    time.normalize(false);
    return time.toMillis(false);
}
Yagna
  • 423
  • 1
  • 5
  • 15

1 Answers1

0

As suggested here, this seems to have done the trick:

SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String date="2012-10-03T22:00:00.000+0000";
try {
    System.out.println(dateTimeFormat.getTimeZone().getDisplayName());
    System.out.println("Today : "+new Date().toString()+ ", Timezone Offset :" +
            +(new Date()).getTimezoneOffset());
    System.out.println("Parsed Date : "+
            dateTimeFormat.parse(date).toString()
            + ", Timezone Offset : "
            +dateTimeFormat.parse(date).getTimezoneOffset());           
} catch (ParseException e) {            
    e.printStackTrace();
}

More specifically, you should have a look at getTimezoneOffset().

Community
  • 1
  • 1
Marcus
  • 6,697
  • 11
  • 46
  • 89