Home>Article>Backend Development> How to convert php unix timestamp to time

How to convert php unix timestamp to time

藏色散人
藏色散人 Original
2020-10-20 09:26:35 3010browse

php Method to convert unix timestamp to time: First create a PHP sample file; then use "date('Y-m-d H:i:s', 1547740800);" to convert the specified unix timestamp into time; finally output the conversion result through echo.

How to convert php unix timestamp to time

Recommended: "PHP Video Tutorial"

PHP Convert UNIX Timestamp UTC Time (TZ Format) Standard Time Methods to convert UNIX UTC GMT time and local time to each other

In PHP programming, we often encounter time in various formats

For example:

unix timestamp: 1547740800

UTC time: 2019-1-18T00:00:00Z

Standard time: 2019-1-18 00:00:00

The above three time formats all represent 0:00:00 on January 18, 2019. How to convert these three time formats in PHP? Here I will teach you

1. Convert UNIX to UTC

echo date('Y-m-dTH:i:sZ', 1547740800); //输出:2019-1-18T00:00:00Z

or

echo date('c',1547740800); //输出:2019-1-18T00:00:00Z+02:00

2. Convert UNIX to standard time

echo date('Y-m-d H:i:s', 1547740800); //输出:2019-1-18 00:00:00

3. Convert UTC Standard time

$utc='2019-1-18T00:00:00Z'; $unix= str_replace(array('T','Z'),' ',$utc); echo $unix; //输出:2019-1-18 00:00:00

4. Convert UTC to UNIX timestamp

$utc='2019-1-18T00:00:00Z'; $time= str_replace(array('T','Z'),' ',$utc); $unix=strtotime($time); echo $unix; //输出:1547740800

5. Convert standard time to UNIX timestamp

$time='2019-1-18 00:00:00'; $unix=strtotime($time); echo $unix; //输出:1547740800

6. Convert standard time to UTC time

$time='2019-1-18 00:00:00'; $unix=strtotime($time); $utc=date('Y-m-dTH:i:sZ', $unix); echo $utc; //输出:2019-1-18T00:00:00Z

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