读书人

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

发布时间: 2012-10-10 13:58:11 作者: rapoo

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

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 );


读书人网 >编程

热点推荐