Parse any string datetime description into a Unix timestamp:
<?php // Set time zone date_default_timezone_set ( " PRC " ) ; $time = strtotime ( " 2018-01-18 08:08:08 " ) ; // Convert the specified date into a timestamp // Print the current time PHP_EOL newline character, compatible with different systems echo $time , PHP_EOL ; // More examples echo strtotime ( " now " ) , PHP_EOL ; echo strtotime ( " now " ) , PHP_EOL ; echo strtotime ( " 10 September 2000 " ) , PHP_EOL ; echo strtotime ( " +1 day " ) , PHP_EOL ; echo strtotime ( " +1 week " ) , PHP_EOL ; echo strtotime ( " +1 week 2 days 4 hours 2 seconds " ) , PHP_EOL ; echo strtotime ( " next Thursday " ) , PHP_EOL ; echo strtotime ( " last Monday " ) , PHP_EOL ; ?>Output result:
15162340881517408272151740827296851520015174946721518013072151820027415174144001517155200
The strtotime() function parses any string datetime description into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT).
Note: If the year is represented using a two-digit format, values 0-69 are mapped to 2000-2069 and values 70-100 are mapped to 1970-2000.
Note: Please note that for dates in m/d/y or dmy format, if the separator is a slash (/), the American m/d/y format is used. If the separator is a dash (-) or a dot (.), the European dmy format is used. To avoid potential errors, you should use YYYY-MM-DD format whenever possible or use the date_create_from_format() function.
int strtotime ( string $time [, int $now = time() ] )
parameter | describe |
---|---|
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. |
Return value: | Returns a timestamp on success, FALSE on failure. |
---|---|
PHP version: | 4+ |
Update log: | PHP 5.3.0: Relative time formats such as this week, previous week, previous week, next week now specify a week from Monday to Sunday instead of using 7 days before and after relative to the current date/time. PHP 5.3.0: 24:00 is now a valid format. PHP 5.2.7: Prior to this, requesting a given date in a month that happened to be the first day of the month would incorrectly add one week to the returned timestamp. The point has now been corrected. PHP 5.1.0: Returns FALSE on failure (previous versions returned -1), and added E_STRICT and E_NOTICE time zone errors. PHP 5.0.2: Now correctly calculates "now" and other relative times based on the current time, rather than today's midnight time. PHP 5.0.0: Allow microseconds (but microseconds are usually ignored). |