This article mainly introduces PHP acquisition of Chinese time and the United States time method, involving PHP time zone selection and date-time related operating skills, very simple and practical, the need for friends can refer to the next
Specific as follows:
China Time:
/** * Access to China time, that is, Shanghai time zone * @param <type> $format * @return <type> */function getchinatime ($format = "y-m-d h:i:s") { $timezone _out = Date_default_timezone_get (); Date_default_timezone_set (' Asia/shanghai '); $chinaTime = Date ($format); Date_default_timezone_set ($timezone _out); return $chinaTime;} Echo Getchinatime ();//output current time, such as: 2017-02-23 11:50:50
US time zone:
America/new_york East US
Encapsulates a different method:
/** * Time Format * @param string $dateformat time format * @param int $timestamp timestamp * @param int $timeoffset time zone offset * @return String */ function qgmdate ($dateformat = ' y-m-d h:i:s ', $timestamp = ", $timeoffset = 8) { if (empty ($timestamp)) { $timesta MP = time (); } $result = Gmdate ($dateformat, $timestamp + $timeoffset * 3600); return $result;} Application examples: Get us time echo qgmdate (' y-m-d h:i:s ', ',-4);//output us time, as: 2017-02-22 23:51:17
The above is the whole content of this article, I hope that everyone's study has helped.