Home  >  Article  >  Backend Development  >  How to implement time format conversion in php

How to implement time format conversion in php

王林
王林Original
2020-11-03 10:49:562854browse

How to implement time format conversion in php: You can use the date() function and strtotime() function to implement time format conversion, such as [date("Y-m-d H:i:s",strtotime('2017-08 -twenty two'));】.

How to implement time format conversion in php

The PHP time format conversion functions include date() and strtotime() functions. PHP’s native time class can also convert time formats.

(Recommended tutorial: php video tutorial)

1. Convert Y-m-d to timestamp Example:

2017-08-22 Convert to timestamp

strtotime(‘2017-08-22’)

2. Convert timestamp to Y-m-d H:i:s

date("Y-m-d H:i:s",strtotime('2017-08-22'));

3. Convert time Ymd format to Y-m-d

date(“Y-m-d”,strtotime("20170822"));

Can also be converted directly using native php classes

var_dum(\DateTime::createFromFormat('Ymd','20170822')->format('Y-m-d'));

4. Get the current timestamp:

time();

or

date('U');

5. Tomorrow’s time format

date("Y-m-d H:i:s",strtotime(+1 day));

Related recommendations: php training

The above is the detailed content of How to implement time format conversion 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