How to convert string to timestamp in php?

青灯夜游
Release: 2023-03-03 07:18:01
Original
9052 people have browsed it

In PHP, you can use the strtotime() function to convert a string into a timestamp. The strtotime() function can convert the date represented by the English text string into a timestamp. It is the inverse function of date() and returns the timestamp successfully, otherwise it returns FALSE.

How to convert string to timestamp in php?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

strtotime() function is used to convert English text characters The date represented by the string is converted into a timestamp, which is the inverse function of date(). It returns the timestamp successfully, otherwise it returns FALSE.

Syntax:

int strtotime ( string time [, int now] )
Copy after login

This function expects a string containing a US English date format and attempts to parse it into a Unix timestamp (since January 1 1970 00: 00:00 GMT), its value is relative to the time given by the now parameter. If this parameter is not provided, the current system time is used.

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.

Parameters:

  • #time: is the parsed date/time string, which is a date represented according to the GNU date input format.

  • now: The timestamp used to calculate the return value.

Return value:

Returns the timestamp if successful, otherwise returns FALSE. Prior to PHP 5.1.0, this function returned -1 on failure. [Recommended learning: "PHP Video Tutorial"]

Example:

"; //输出明天此时的时间戳 ?>
Copy after login

Recommended learning:PHP Programming from Beginner to Mastery

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

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!