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

藏色散人
Release: 2023-03-11 06:48:02
Original
3558 people have browsed it

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)
Copy after login
var_dump(date('Y-m-d H:i:s', 1502204401)); //H 24小时制 2017-08-08 23:00:01
Copy after login

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

Method of outputting 12-hour time:

echo date("Y-m-d h:i:s");
Copy after login

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

The output to the browser is:

2014-03-01 14:09:15
14-03-01 02:09:15
Copy after login

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!

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