Home >Backend Development >PHP Problem >How to convert php time format

How to convert php time format

L
LOriginal
2020-05-29 15:53:172706browse

How to convert php time format

php time format conversion

The php time format conversion functions include date(), strtotime() functions, PHP's native time class can also convert time formats.

1. Convert Y-m-d to timestamp. Example: 2017-08-22 is converted 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. The time Ymd format is converted into Y-m-d date("Y-m-d",strtotime("20170822 "));

You can also directly convert using native PHP classes var_dum(\DateTime::createFromFormat('Ymd','20170822')->format('Y-m-d'));

4. Get the current timestamp: 1. time(); 2. date('U');

5. Tomorrow's time format date("Y-m-d H:i:s",strtotime( 1 day));

Get the date for a period of time

$end = new \DateTime($end);
$end = $end->modify( '+1 day' );
$interval = new \DateInterval('P1D');// yii中引用原生的php类加\,因为有命名空间
$daterange = new \DatePeriod($start, $interval ,$end);//查询这个时间段内所有的日期
foreach($daterange as $date){
    $single_date = $date->format("Ymd");//每个日期都改成20170022的格式
    $this->run_curl($url,$post_data,$project,$flow,$single_date,$timeBegin,$timeEnd);
}

$datarange is the date within the time period.

Recommended: "PHP Tutorial"

The above is the detailed content of How to convert php time format. 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
Previous article:what does $ mean in phpNext article:what does $ mean in php