Home  >  Article  >  Backend Development  >  How to convert time string to timestamp in php

How to convert time string to timestamp in php

王林
王林Original
2020-08-28 13:18:374259browse

php method to convert a time string into a timestamp: You can use the built-in function strtotime() to achieve this. The strtotime() function can parse the date or time description of any English text into a Unix timestamp, returning the timestamp if successful, otherwise it returns false.

How to convert time string to timestamp in php

PHP provides us with a large number of built-in functions, including the strtotime() function, which can parse any English text date or time description into Unix time Stamp (number of seconds since January 1 1970 00:00:00 GMT), very convenient to use.

(Video tutorial recommendation: php video tutorial)

Syntax:

strtotime(time,now);

Parameter description:

time Required. Specifies a date/time string.​

now ​ Optional. Specifies the timestamp used to calculate the return value. If this parameter is omitted, the current time is used.

Return value:

If successful, return timestamp, if failed, return FALSE.

(Related recommendations: php training)

Code sample:

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

The above is the detailed content of How to convert time string to timestamp in php. 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