0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP7.3以降でAsia/TokyoでUTCとの時差が9:18:59になることがある

Posted at

下記のようなコードで検証。

<?php
$zero = new DateTime('0000-01-01', new DateTimeZone('utc'));
$zero->setTimezone(new DateTimeZone('Asia/Tokyo'));
var_dump($zero->format('Y-m-d H:i:s')); // string(19) "0000-01-01 09:18:59"

$y1887 = new DateTime('1887-01-01', new DateTimeZone('utc'));
$y1887->setTimezone(new DateTimeZone('Asia/Tokyo'));
var_dump($y1887->format('Y-m-d H:i:s')); // string(19) "1887-01-01 09:18:59"

$y1888 = new DateTime('1888-01-01', new DateTimeZone('utc'));
$y1888->setTimezone(new DateTimeZone('Asia/Tokyo'));
var_dump($y1888->format('Y-m-d H:i:s')); // string(19) "1888-01-01 09:00:00"

$y2000 = new DateTime('2000-01-01', new DateTimeZone('utc'));
$y2000->setTimezone(new DateTimeZone('Asia/Tokyo'));
var_dump($y2000->format('Y-m-d H:i:s')); // string(19) "2000-01-01 09:00:00"

なんで 1887年以前だと"9:15:59"なん?ってのは 18分59秒をめぐって日本標準時の歴史をひもとくことに - エムスリーテックブログ に詳しく書かれてます。

PHP7.2までだと発生しなかったようなので、PHP7.3になってから、いつの時差なのかを考慮するようになったのかなと思います。

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?