How to determine what time it is in php: 1. Use the time() or strtotime() function to get the timestamp representing the current time; 2. Use "date("H:i:s", time Stamp)" statement formats the timestamp, converts it into "hour:minute:second" format and outputs it.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php determines the current What are the points
#1. Get the timestamp representing the current time
Method 1: Use the time() function
time () function returns the current time in seconds since the Unix epoch (January 1 1970 00:00:00 GMT).
Syntax:
time()
Method 2: strtotime() function
strtotime() function parses any string datetime description into a Unix timestamp (since January 1 1970 seconds since 00:00:00 GMT).
Syntax:
strtotime("now")
2. Use date() function to format timestamp
date("H:i:s",时间戳)
Full code:
<?php header("Content-type:text/html;charset=utf-8"); ini_set('date.timezone', 'Asia/Shanghai');//设置时区 $time=time(); echo "当前是:".date("H:i:s",$time); ?>
Extended knowledge:
The world is divided into 24 time zones. Each time zone has its own local time. The local time of each time zone differs by 1 at the same time. ~23 hours, for example, the difference between local time in London, UK and local time in Beijing is 8 hours. To set the time zone, please refer to the article "How to convert time zone time in php?" 》
Recommended learning:《PHP Video Tutorial》
The above is the detailed content of How to determine the current time in php. For more information, please follow other related articles on the PHP Chinese website!