transform Time in java.util.Date from one timezone to another timezone - Android java.util

Android examples for java.util:Timezone

Description

transform Time in java.util.Date from one timezone to another timezone

Demo Code

import java.util.Date;
import java.util.TimeZone;

public class Main {

  public static Date transformTime(Date date, TimeZone oldZone, TimeZone newZone) {
    Date finalDate = null;/*from  w  w w  .ja  v a  2s  . c om*/
    if (date != null) {
      int timeOffset = oldZone.getOffset(date.getTime()) - newZone.getOffset(date.getTime());
      finalDate = new Date(date.getTime() - timeOffset);
    }
    return finalDate;
  }

}

Related Tutorials