Home >Backend Development >PHP Problem >How to use PHP time conversion function?
PHP time conversion function
The time conversion function in PHP is "strtotime()". The function of this function is to convert any English text The date or time description is parsed into a Unix timestamp, and its syntax is "strtotime(time,now)". If the function succeeds, it returns the timestamp, otherwise it returns FALSE.
Simple example
<?php echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n"; ?>
Failure check
<?php $str = 'Not Good'; // previous to PHP 5.1.0 you would compare with -1, instead of false if (($timestamp = strtotime($str)) === false) { echo "The string ($str) is bogus"; } else { echo "$str == " . date('l dS of F Y h:i:s A', $timestamp); } ?>
Recommended tutorial: "PHP Tutorial》
The above is the detailed content of How to use PHP time conversion function?. For more information, please follow other related articles on the PHP Chinese website!