Home > Backend Development > PHP Problem > How to convert php timestamp to t format

How to convert php timestamp to t format

藏色散人
Release: 2023-03-20 11:04:01
Original
2875 people have browsed it

How to convert php timestamp to t format: 1. Create a php sample file; 2. Use the "date('Y-m-dTH:i:sZ', 1547740800);" method or "date( 'c',1547740800);" method can convert unix timestamp to UTC.

How to convert php timestamp to t format

The operating environment of this tutorial: Windows 10 system, PHP8.1, Dell G3 computer.

How to convert php timestamp to t format?

PHP converts UNIX timestamp UTC time (TZ format) Standard time method UNIX UTC GMT time and local time conversion

We often encounter various differences in PHP programming Format time

For example:

unix时间戳:1547740800
UTC时间:2019-1-18T00:00:00Z
标准时间:2019-1-18 00:00:00
Copy after login

The above three time formats all represent 0:00 on January 18, 2019 Minutes and seconds, how to convert these three time formats in PHP? Here we will teach you

1. Convert UNIX to UTC

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

or

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

2. Convert UNIX to standard time

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

3. Convert UTC to standard time

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

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

5. Convert standard time to UNIX timestamp

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

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

Recommended learning: "PHP Video Tutorial"

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