Home >Backend Development >PHP Problem >How to get timestamp and convert it to 24-hour format in php

How to get timestamp and convert it to 24-hour format in php

藏色散人
藏色散人Original
2021-07-01 09:26:073592browse

In PHP, you can use the date function to convert the timestamp into a 24-hour format. The implementation statement is such as "var_dump(date('Y-m-d H:i:s', 1502204401));".

How to get timestamp and convert it to 24-hour format in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php get the timestamp and convert it to 24 Hourly time?

date() Convert timestamp to date

date(format,timestamp)
var_dump(date('Y-m-d H:i:s', 1502204401)); //H 24小时制 2017-08-08 23:00:01

date() in php outputs 12-hour and 24-hour format

php date () Method of outputting 24-hour time:

echo date("Y-m-d H:i:s");

Method of outputting 12-hour time:

echo date("Y-m-d H:i:s");

The difference between the two methods is the difference between upper and lower case, just change the letters.

Capital Y represents the complete year, such as: 2014, while lowercase y represents the abbreviation of the year, such as: 14

Capital H represents the 24-hour clock, while lowercase h represents the output of 12 Hourly time.

The following code:

echo date("Y-m-d H:i:s")."<br />";
echo date("y-m-d h:i:s");

The output to the browser is:

2014-03-01 14:09:15
14-03-01 02:09:15

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to get timestamp and convert it to 24-hour format 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