3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @link https://stackoverflow.com/a/13129856/367456 */ $formats = array( 'today midnight', 'midnight', 'today', 'TODAY', 'MidNight', 'ToDaY', 'tomorrow', 'UTC today', 'today Z', 'today Europe/Berlin', 'Asia/Shanghai today', 'Asia/Shanghai', 'HKST today', ); /** * give each time (unix timestamp) its own color * * @param $time * @return string */ function time_color($time) { static $colors = array('black', 'copper', 'blue', 'lime', 'green', 'pink', 'red'); static $coloredTime = array(-1 => ' ?! '); if (!isset($coloredTime[$time])) { $coloredTime[$time] = array_pop($colors); } return $coloredTime[$time]; } $time = strtotime('UTC 2020-01-01 00:00:00'); $format1 = "(default time-zone is ..: %s)\n"; if (is_callable('date_default_timezone_get')) { printf($format1, date_default_timezone_get()); } else { printf($format1, '??? (unknown)'); } printf("UTC time is ............: [%-6s] %d (script-time, UTC 2020-01-01 00:00:00)\n", time_color($time), $time); foreach ($formats as $format) { $strToTime = strtotime($format, $time); printf("%'.-24s: [%-6s] %d\n", "$format ", time_color($strToTime), $strToTime); }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.29, 8.0.0 - 8.0.19, 8.1.0 - 8.1.6
(default time-zone is ..: Europe/Amsterdam) UTC time is ............: [red ] 1577836800 (script-time, UTC 2020-01-01 00:00:00) today midnight .........: [pink ] 1577833200 midnight ...............: [pink ] 1577833200 today ..................: [pink ] 1577833200 TODAY ..................: [pink ] 1577833200 MidNight ...............: [pink ] 1577833200 ToDaY ..................: [pink ] 1577833200 tomorrow ...............: [green ] 1577919600 UTC today ..............: [red ] 1577836800 today Z ................: [red ] 1577836800 today Europe/Berlin ....: [pink ] 1577833200 Asia/Shanghai today ....: [lime ] 1577808000 Asia/Shanghai ..........: [blue ] 1577811600 HKST today .............: [copper] 1577804400

preferences:
52.35 ms | 411 KiB | 5 Q