Home  >  Article  >  Backend Development  >  What is the time format conversion function in php

What is the time format conversion function in php

王林
王林Original
2020-12-02 18:06:123292browse

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’);

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"));

You can also use native php classes to convert directly

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

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!

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