How to convert time string to timestamp in php

王林
Release: 2023-03-05 11:34:02
Original
4159 people have browsed it

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);
Copy after login

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:

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

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!

Related labels:
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!