Home >Backend Development >PHP Problem >php string to timestamp

php string to timestamp

Guanhui
GuanhuiOriginal
2020-05-01 14:49:494748browse

php string to timestamp

php string to timestamp

In PHP, you can use the "strtotime()" function to convert a string to a timestamp.

strtotime description and usage

strtotime Parses the date and time description of any string into a Unix timestamp

strtotime ( string $time [, int $now = time() ] ) : int

This function is expected to accept a string containing the United States A string in English date format and attempts to parse it into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT) relative to the time given by the now parameter, or if this parameter is not provided The current system time.

This function will use the TZ environment variable (if any) to calculate the timestamp. Since PHP 5.1.0 there is an easier way to define the time zone used in all date/time functions. This process is documented on the date_default_timezone_get() function page.

strtotime parameter

time: date/time string. The correct format is explained in Date and Time Format.

now: The timestamp used to calculate the return value.

strtotime return value

Returns the timestamp if successful, otherwise returns FALSE. Prior to PHP 5.1.0, this function returned -1 on failure.



The above is the detailed content of php string to timestamp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn