/** * Sets the time zone of the datetime, changing the chronology and field values. * * <p>Changing the zone using this method retains the millisecond instant. The millisecond instant * is adjusted in the new zone to compensate. * * <p>chronology. Setting the time zone does not affect the millisecond value of this instant. * * <p>If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZoneRetainFields */ public void setZone(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); Chronology chrono = getChronology(); if (chrono.getZone() != newZone) { setChronology(chrono.withZone(newZone)); // set via this class not super } }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * * <p>Changing the zone using this method retains the field values. The millisecond instant is * adjusted in the new zone to compensate. * * <p>If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }