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.
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] )
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:
<?php echo strtotime("2009-10-21 16:00:10"); //输出 1256112010 echo strtotime("10 September 2008"); //输出 1220976000 echo strtotime("+1 day"), "<br />"; //输出明天此时的时间戳 ?>
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
