Php obtains server time (solving the eight-hour gap)

Source: Internet
Author: User

Php obtains the server time (solving the eight-hour gap problem). The following three obtain the current time to solve the eight-hour gap problem, you only need to add date_default_timezone_set (\ "Asia/Chongqing \"); To solve the time zone problem. Generally, the date () and time () functions will have time difference issues.

Php tutorial to get server time (solve the problem of 8 hours gap)
The following three methods can solve the eight-hour gap. You only need to add date_default_timezone_set ("asia/chongqing") before obtaining the time, generally, the date () and time () functions have time difference issues.

/**
* Get the current server Date and Time
*/

Function get_server_datetime ()
{
Date_default_timezone_set ("asia/chongqing ");
Return date ("y-m-d h: I: s ");
}

/**
* Get the current server date
*/

Function get_server_date ()
{
Date_default_timezone_set ("asia/chongqing ");
Return date ("ymd ");
}

/**
* Get the current server time
*/

Function get_time ()
{
Date_default_timezone_set ("asia/chongqing ");
$ Timeval ["h"] = date ("h"); // hour
$ Timeval ["I"] = date ("I"); // minute
$ Timeval ["s"] = date ("s"); // second
Return $ timeval;
}

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.