Home>Article>Backend Development> How to convert date to timestamp in php

How to convert date to timestamp in php

藏色散人
藏色散人 Original
2020-07-28 10:08:01 2848browse

You can use the strtotime function in PHP to convert date into a timestamp, because the strtotime function is used to parse the date or time description of any English text into a Unix timestamp. The syntax is "strtotime(time,now) );".

How to convert date to timestamp in php

Recommended: "PHP Tutorial"

php date to timestamp

date('Y-m-d H:i:s', 1156219870);

1. Use function to convert UNIX timestamp to date: date()

General form: date('Y-m-d H:i:s', 1156219870);

2. Use function to convert date to UNIX timestamp: strtotime()

General form: strtotime('2010-03-24 08:15 :42');

strtotime() function parses the date or time description of any English text into a Unix timestamp

3. This method completes the conversion in the PHP program. The advantage is that no matter Whether the data obtained by querying in the database can be converted, the conversion range is not limited. The disadvantage is that it takes up the parsing time of the PHP parser and is relatively slow.

How to convert date to timestamp in php##

The above is the detailed content of How to convert date 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