Home >Backend Development >PHP Problem >What are the ways to get the current timestamp in php
How to get the current timestamp in php: 1. Use the time() function directly, with the syntax "time()"; 2. Use the strtotime() function, with the syntax "strtotime("now")".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php gets the current time Stamping method
1. Use time()
time() function returns the Unix epoch (January 1 1970 00:00:00 GMT) the current time in seconds.
Syntax: time();
Returns an integer containing the Unix timestamp of the current time.
Example:
<?php echo time(); ?>
Output:
1635851460
2. Use strtotime()
strtotime() function to Any string datetime description resolves to a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT).
语法:strtotime ( $time [, $now = time() ] )
time: required. Specifies a date/time string.
#now: Optional. Specifies the timestamp used to calculate the return value. If this parameter is omitted, the current time is used.
Example: Current timestamp
<?php header("Content-type:text/html;charset=utf-8"); echo strtotime("now"); ?>
Output:
1635851553
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What are the ways to get the current timestamp in php. For more information, please follow other related articles on the PHP Chinese website!