<?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);
}
preferences:
27.38 ms | 409 KiB | 5 Q