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()before getting the time
{
Date_default_timezone_set("asia/chongqing");
$timeval["h"] = date("h"); //Hour
$timeval["i"] = date("i"); //minutes
$timeval["s"] = date("s"); //Seconds
Return $timeval;
}