Chuyển đổi các múi giờ
Converting Between Different Time Zones
<?php
// function to get time
// for another time zone
// given a specific timestamp and hour offset from GMT
function getLocalTime($ts, $offset) {
// performs conversion
// returns UNIX timestamp
return ($ts - date("Z", $ts)) + (3600 * $offset);
}
// get current local time in Singapore
// result: "00:11:26 31-10-06 SST"
echo date("H:i:s d-m-y", getLocalTime(mktime(), 8)) . " SST \n";
// get current local time in India
// result: "21:41:26 30-10-06 IST"
echo date("H:i:s d-m-y", getLocalTime(mktime(), +5.5)) . " IST \n";
// get current local time in USA (Eastern)
// result: "11:11:26 30-10-06 EST"
echo date("H:i:s d-m-y", getLocalTime(mktime(), -5)) . " EST \n";
// get current local time in USA (Pacific)
// result: "08:11:26 30-10-06 PST"
echo date("H:i:s d-m-y", getLocalTime(mktime(), -8)) . " PST \n";
// get time in GMT
// when it is 04:30 AM in India
// result: "23:00:00 01-02-05 GMT "
echo date("H:i:s d-m-y", getLocalTime(mktime(4,30,0,2,2,2005), 0)) .?
" GMT \n";
?>
Popularity: 71% [?]
No comments yet.