What is the time format conversion function in php

王林
Release: 2023-03-07 22:42:01
Original
3296 people have browsed it

The time format conversion functions in php are strtotime and date. For example, to convert the timestamp to [Y-m-d H:i:s], the code is [date("Y-m-d H:i:s",strtotime(' 2020-08-22'));].

What is the time format conversion function in php

The operating environment of this tutorial: windows10 system, php5.4. This article is applicable to all brands of computers.

php time format conversion function: date(), strtotime() function, PHP’s native time class can also convert time format.

(Learning recommendation: 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

You can also use native php classes to convert directly

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

Related recommendations: php training

The above is the detailed content of What is the time format conversion function 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!