This article describes how to obtain the Chinese time (Shanghai time zone) and American Time in PHP. it involves php time zone selection and date and time related operations. it is very simple and practical, for more information about how to obtain Chinese time (Shanghai time zone) and American time by using PHP, see the following example. We will share this with you for your reference. The details are as follows:
China Time:
/*** Get China time, that is, Shanghai time zone time * @ param
$ Format * @ return
*/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 the current time, for example, 11:50:50
US time zone:
America/New_York east USA
Another method is encapsulated:
/*** Format Time ** @ param string $ dateformat time format * @ param int $ timestamp * @ param int $ timeoffset time zone offset * @ return string */function qgmdate ($ dateformat = 'Y-m-d H: i: S', $ timestamp = '', $ timeoffset = 8) {if (empty ($ timestamp) {$ timestamp = time ();} $ result = gmdate ($ dateformat, $ timestamp + $ timeoffset * 3600); return $ result;} // example of an application: obtain the echo qgmdate ('Y-m-d H: I: S', '',-4) at the U.S. time, for example, 23:51:17.
For more PHP articles related to Chinese time and American time, please refer to PHP Chinese network!