Home  >  Article  >  Backend Development  >  How to convert timestamp to time format in php

How to convert timestamp to time format in php

藏色散人
藏色散人Original
2021-06-17 09:34:543196browse

In PHP, the timestamp can be converted into time format through the "date()" function. The conversion syntax is "date(format, timestamp)", and the format parameter specifies the format of the timestamp.

How to convert timestamp to time format in php

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

How does php convert timestamp to time? Format?

PHP timestamp and date conversion

Timestamp to date date()

date(format,timestamp)

format required. Specifies the format of the timestamp.

timestamp Optional. Specify timestamp. The default is the current time and date

For example: date('Y-m-d H:i:s', specific timestamp)

Y: Year (four digits) in uppercase letters

m: Month (two digits, add 0 if the first digit is missing) Lowercase

d: Day (two digits, add 0 if the first digit is missing) Lowercase

H: hour with a leading zero 24 hours Hour format

h: hour 12 hours with leading zero Hour format

i: minute with leading zero

s: second with leading zero (00 -59)

a: Lowercase noon and afternoon (am or pm)

The distinction between upper and lower case is very important, such as the following example:

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

Recommended study: "PHP video tutorial

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