中國時間:
- /**
- * 獲取中國時間,即上海時區時間
- * @param <type> $format
- * @return <type>
- */
- functiongetChinaTime($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;
- }
- echogetChinaTime();//輸出當前時間,如:2017-02-23 11:50:50
美國時區:
America/New_York 美國東部
封裝了另外一個方法:
- /**
- * 時間<a href="http://www.111cn.net/zhuanti/geshihua/" class="anchor" target="_blank">格式化</a>
- * @param string $dateformat 時間格式
- * @param int $timestamp 時間戳
- * @param int $timeoffset 時區偏差
- * @return string
- */
- functionqgmdate($dateformat='Y-m-d H:i:s',$timestamp='',$timeoffset= 8) {
- if(emptyempty($timestamp)) {
- $timestamp= time();
- }
- $result=gmdate($dateformat,$timestamp+$timeoffset* 3600);
- return$result;
- } //Vevb.com
- //應用舉例:獲取美國時間
- echoqgmdate('Y-m-d H:i:s','', -4);//輸出美國時間,如:2017-02-22 23:51:17
新聞熱點
疑難解答