Home >Backend Development >PHP Problem >How to convert specified timestamp to date in php

How to convert specified timestamp to date in php

王林
王林Original
2021-06-25 10:36:552241browse

The way PHP converts a specified timestamp into a date is to use the date function, such as [date('Y-m-d H:i:s', 1156219870);]. The advantage of this method is that the conversion range is not limited.

How to convert specified timestamp to date in php

The operating environment of this article: windows10 system, php7.3, thinkpad t480 computer.

It is very simple for us to convert the specified timestamp into a date. It can be done directly using the date function.

The advantage of using this method is that it can be converted regardless of whether the data obtained by querying in the database is, and the conversion range is not limited. However, the disadvantage is that it takes up the parsing time of the PHP parser and is relatively slow.

The function used to convert UNIX timestamp to date: date()

General form:

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

The function used to convert date to UNIX timestamp: strtotime()

General form:

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

Related video sharing: php video tutorial

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