PHP retrieves Chinese and American time

Source: Internet
Author: User
Tags american time
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.