Home > Backend Development > PHP Tutorial > PHP date and time functions_PHP tutorial

PHP date and time functions_PHP tutorial

WBOY
Release: 2016-07-13 09:57:15
Original
908 people have browsed it

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 8th 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. If you use "d", it will return the date from 01 to 31 of the current month

4. Parse date and time into Unix timestamp

Use the maketime() function to generate the corresponding Unix timestamp


Let’s look at an 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)."
";
echo "There are ".$day." days until January 1, 2016."."
";


?>

The running result is:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/984113.htmlTechArticlePHP date and time functions 1. Time zone setting method 1: Set date.timezone=Asia/Hong_Kong in php.ini , Make the system default time to the East 8th District. Method 2: Use the function date_default_timezo...
Related labels:
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