我试图通过使用PHP:http://php.net/manual/en/timezones.php中的时区函数来显示两个位置之间的时间差。
假设我从上面的链接中选择了英国和中国,我可以在php页面上显示位置的时间,但是如何显示这两个位置之间的时间差呢?
也就是说,在英国是12:49,中国是18:49。我需要在几个小时内显示这两个值之间的差异!
任何帮助都会很好。
编辑:下面是我如何在PHP中显示特定位置的当前时间:
<div style="visibility:hidden;"><?php
date_default_timezone_set('Europe/Moscow');
echo 'Current Time In Moscow: ' . date('H:i:s.A') . PHP_EOL ;
?>
<div style="visibility:hidden;"><?php
date_default_timezone_set('Asia/Shanghai');
echo 'Current Time In Beijing: ' . date('H:i:s.A') . PHP_EOL ;
?>我也在Google上找到了这个链接,但是我不知道该怎么做:http://kukunotes.wordpress.com/2013/04/28/php-find-time-difference-between-two-countries-by-country-code/。
发布于 2013-08-21 12:07:04
function get_timezone_offset( $origin_tz, $remote_tz ) {
$timezone1 = new DateTimeZone( $origin_tz );
$timezone2 = new DateTimeZone( $remote_tz );
$datetime1 = new DateTime("now", $timezone1);
$datetime2 = new DateTime("now", $timezone2);
$offset = $timezone1->getOffset($datetime1) - $timezone2->getOffset($datetime2);
return $offset;
}
$offset = get_timezone_offset( 'Europe/London', 'Asia/Shanghai' );
// convert offset to hours
echo $offset/3600;https://stackoverflow.com/questions/18356647
复制相似问题