How to use php time function?

藏色散人
Release: 2023-04-06 18:34:01
Original
4475 people have browsed it

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())".

How to use php time function?

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;
?>
Copy after login

Output:

1523947811
Copy after login

Example 2: time() date() converts unix timestamp to current date

<?php
$time=time();
echo "当前时间戳为:".$time."<br>";
echo "转换为具体时间为:".(date("Y-m-d",$time));
?>
Copy after login

Output:

当前时间戳为:1524705185
转换为具体时间为:2018-04-26
Copy after login

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!

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