public function testChangeTimeZone() { $timezone1 = TimeZone::parse('UTC'); $timezone2 = TimeZone::parse('America/Los_Angeles'); $datetime1 = ZonedDateTime::ofInstant(Instant::of(1000000000), $timezone1); $datetime2 = $datetime1->withTimeZoneSameInstant($timezone2); $this->assertSame($timezone1, $datetime1->getTimezone()); $this->assertSame($timezone2, $datetime2->getTimezone()); $this->assertSame('2001-09-08T18:46:40', (string) $datetime2->getDateTime()); $datetime2 = $datetime1->withTimeZoneSameLocal($timezone2); $this->assertSame($timezone1, $datetime1->getTimezone()); $this->assertSame($timezone2, $datetime2->getTimezone()); $this->assertSame('2001-09-09T01:46:40', (string) $datetime2->getDateTime()); }
/** * @return string */ public function __toString() { return (string) ZonedDateTime::ofInstant($this, TimeZone::utc()); }
/** * Returns a copy of this ZonedDateTime with the specified Duration added. * * @param Duration $duration * * @return ZonedDateTime */ public function plusDuration(Duration $duration) { return ZonedDateTime::ofInstant($this->getInstant()->plus($duration), $this->timeZone); }