Home > Article > Backend Development > PHP date and time functions
1. Time zone setting
Method 1: Set date.timezone=Asia/Hong_Kong in php.ini so that the system default time is East 8 District
Method 2: Use the function date_default_timezone_set() to set the time zone to date_default_timezone_set("Asia/Hong_Kong" )
2. Get the current timestamp
Use the time() function to directly return the current time and date. The timestamp represents the number of seconds from 0:00:00 on January 1, 1970 to the running time of this program
3. Get the current date and time
Use the date() function to return the current date. date() has many parameters. For example, using "d" will return the date from 01 to 31 of the current month
4. Parse the date and time into a Unix timestamp
Use the maketime() function to generate the corresponding Unix timestamp
Look at one below Example:
date_default_timezone_set("Asia/Hong_Kong");
$timefuture = mktime(0,0,0,01,01,2016);
$timenow = time();
$timecount = $ timefuture - $timenow;
$day = round($timecount/86400);
echo date("The current time is: Y year m month d day [l]H point i minute s second",$timenow)."< br>";
echo "There are ".$day." days before January 1, 2016. "."
";
?>
The running result is:
The above has introduced the PHP date and time functions, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.