PHP - strtotime
Trieda
Metóda - strtotime
(PHP 4, PHP 5, PHP 7)
The function converts a given date and time as an English text to the Unix timestamp (the number of seconds since 1/1/1970).
Beware: This function is not suitable to be used in
mathematical operations. For working with date and time rather use the
DateTime class.
Procedurálne
- function strtotime (string $time, int $now = time()) : int
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $time | string | The input date. | |
| $now | int | time() | The date used as the base for relative operations. See the example. |
Mávratovej hodnoty
Vracia: int
Returns Unix timestamp on success, false otherwise.
Príklady
Example:
<?php
echo strtotime('now') . "\n"; // now
echo strtotime('+2 week') . "\n"; // add 14 days
echo strtotime('+1 day') . "\n"; // add 1 day
echo strtotime('next Sunday') . "\n"; // get next Sunday
$relative = 1483228800; // 1 January 2017 00:00
echo strtotime('now', $relative) . "\n"; // "now" relative to given date
echo strtotime('+ 1 week', $relative) . "\n"; // add 7 days to given date
Invalid date:
<?php
$timestamp = strtotime('Hello World!');
if ($timestamp)
echo 'Timestamp of given date is: ' . $timestamp;
else
echo 'Invalid date!';
