首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

本土时区转化为他国时区时间

2012-10-10 
本地时区转化为他国时区时间function offset($remote, $local NULL, $now NULL){if ($local NULL)

本地时区转化为他国时区时间

function offset($remote, $local = NULL, $now = NULL){if ($local === NULL){// Use the default timezone$local = date_default_timezone_get();}if (is_int($now)){// Convert the timestamp into a string$now = date(DateTime::RFC2822, $now);}// Create timezone objects$zone_remote = new DateTimeZone($remote);$zone_local  = new DateTimeZone($local);// Create date objects from timezones$time_remote = new DateTime($now, $zone_remote);$time_local  = new DateTime($now, $zone_local);// Find the offset$offset = $zone_remote->getOffset($time_remote) - $zone_local->getOffset($time_local);return $offset;}$now = '2012-09-14 19:12:31';$offset = offset( 'Asia/Bangkok', 'Asia/Shanghai', $now );echo $now,' : ',date( 'Y-m-d H:i:s', strtotime( $now )+$offset );


热点排行