Home > Backend Development > PHP Tutorial > Get the server time in php (solve the 8-hour gap problem)_PHP tutorial

Get the server time in php (solve the 8-hour gap problem)_PHP tutorial

WBOY
Release: 2016-07-13 10:53:54
Original
1439 people have browsed it

php gets the server time (solve the 8-hour gap problem) The following three methods for obtaining the current time can solve the 8-hour gap problem very well. Just add date_default_timezone_set("Asia/Chongqing"); before getting the time to solve the time zone problem. Generally, we use date(), time() Functions all have time differences.

php tutorial to get the server time (solve the 8-hour gap problem)
The following three methods for obtaining the current time can solve the 8-hour gap problem very well. Just add date_default_timezone_set("asia/chongqing"); before getting the time to solve the time zone problem. Generally, we use date(), time() Functions all have time differences.

/**
* Get the current date and time of the server
​*/

function get_server_datetime()
{
date_default_timezone_set("asia/chongqing");
return date("y-m-d h:i:s");
}

/**
* Get the current date of the server
​*/

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"); //minutes
$timeval["s"] = date("s"); //Seconds
Return $timeval;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632366.htmlTechArticlephp gets the server time (solve the 8-hour gap problem) The following three methods are good solutions for getting the current time 8 For hour gap issues, just add date_default_timezone_...
before getting the time
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template