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

How to implement time format conversion in php

王林
Release: 2023-03-07 06:04:02
Original
2893 people have browsed it

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

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

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

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

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

Can also be converted directly using native php classes

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

4. Get the current timestamp:

time();
Copy after login

or

date('U');
Copy after login

5. Tomorrow’s time format

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

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!

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