Easy Tutorial
❮ Func String Quoted Printable Decode Php Imagecolorclosest ❯

PHP strtotime() Function

PHP Date/Time Reference Manual

Example

Parse any string date-time description into a Unix timestamp:

<?php
// Set timezone
date_default_timezone_set("PRC");
$time = strtotime("2018-01-18 08:08:08");  // Convert specified date to timestamp
// Print current time  PHP_EOL for line break, 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:

1516234088
1517408272
1517408272
968515200
1517494672
1518013072
1518200274
1517414400
1517155200

Definition and Usage

The strtotime() function parses any English textual date-time description into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).

Note: If the year is specified in a two-digit format, values 0-69 map to 2000-2069 and values 70-100 map to 1970-2000.

Note: Be aware of the date formats m/d/y or d-m-y. If the separator is a slash (/), the American m/d/y is assumed. If the separator is a dash (-) or a dot (.), the European d-m-y format is assumed. To avoid potential errors, you should use YYYY-MM-DD format or utilize the date_create_from_format() function.

Syntax

int strtotime ( string $time [, int $now = time() ] )
Parameter Description
time Required. Specifies the date/time string.
now Optional. Specifies the timestamp used to calculate the return value. If omitted, the current time is used.

Technical Details

Return Value: Returns a timestamp on success, FALSE on failure.
PHP Version: 4+
--- ---
Changelog: PHP 5.3.0: Relative time formats like this week, last week, previous week, next week now define a week as starting from Monday to Sunday, rather than using the previous 7 days relative to the current date/time. <br>PHP 5.3.0: <br> Now 24:00 is a valid format. <br>PHP 5.2.7: In previous versions, if a given date of a month was the first day of that month, it would incorrectly add a week to the returned timestamp, which has now been corrected. <br>PHP 5.1.0: Returns FALSE on failure (previously returned -1), and issues E_STRICT and E_NOTICE timezone errors. <br>PHP 5.0.2: Now correctly calculates "now" and other relative times based on the current time, rather than today's midnight. <br>PHP 5.0.0: Microseconds are allowed (but are generally ignored).
--- ---
❮ Func String Quoted Printable Decode Php Imagecolorclosest ❯