Home >Backend Development >PHP Problem >How to convert date to timestamp in php
The way PHP converts dates into timestamps is: You can use the strtotime() function to achieve this. This function can parse any string datetime description into a Unix timestamp, returning FALSE on failure. The specific usage method is: [strtotime("2009-10-21 16:00:10")].
strtotime() function parses any string datetime description into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT ), returns the timestamp if successful, and returns FALSE if failed.
(Recommended tutorial: php tutorial)
Grammar format:
int strtotime ( string $time [, int $now = time() ] )
Parameter description:
time is 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.
Code implementation:
<?php echo strtotime("2009-10-21 16:00:10"); //输出 1256112010 echo strtotime("10 September 2008"); //输出 1220976000 echo strtotime("+1 day"), "<br />";//输出明天此时的时间戳 ?>
The above is the detailed content of How to convert date to timestamp in php. For more information, please follow other related articles on the PHP Chinese website!