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

How to convert specified timestamp to date in php

王林
Release: 2023-03-10 21:36:01
Original
2221 people have browsed it

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

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

General form:

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

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template