Ways to get PHP time in China and American Time

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


Related Article

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.