time() is a built-in function in PHP, used to return the number of seconds from the Unix epoch to the current time (unix timestamp), the syntax is "time();", no parameters; then you can use PHP The date() function in will convert the returned seconds to the current date, with the syntax "date("Y-m-d",time())".
time() function
Function: Returns the unix timestamp of the current time
Syntax :time()
Parameters: The time() function only returns the unix timestamp of the current time, without parameters.
Description: Returns the number of seconds since the Unix epoch (00:00:00 GMT on January 1, 1970) to the current time.
Example 1
<?php $i = time(); echo $i; ?>
Output:
1523947811
Example 2: time() date() converts unix timestamp to current date
<?php $time=time(); echo "当前时间戳为:".$time."<br>"; echo "转换为具体时间为:".(date("Y-m-d",$time)); ?>
Output:
当前时间戳为:1524705185 转换为具体时间为:2018-04-26
The above is the detailed content of How to use php time function?. For more information, please follow other related articles on the PHP Chinese website!