Home  >  Article  >  Backend Development  >  How to format display time date function in PHP

How to format display time date function in PHP

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-05-25 17:22:562702browse

This article will introduce to you how to format the date() function to display time in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to format display time date function in PHP

date() Function

Function: Used to format time and return a string.

Syntax: string date( string format [, int timestamp] ), where the parameter format represents the time formatting method; the optional parameter timestamp represents the timestamp, and the default is time(), That is the current time.

Time formatting method

How to format display time date function in PHP

Example one

<?php
$date=date_create("2016-09-25");
echo date_format($date,"Y/m/d H:i:s");
?>

Example two

date("Y-m-d",time());       //显示格式如 2008-12-01
date("Y.m.d",time());       //显示格式如 2008.12.01
date("M d Y",time());       //显示格式如 Dec 01 2008
date("Y-m-d H:i",time());   //显示格式如 2008-12-01 12:01

date_default_timezone_set('PRC') ;

$start_time="2017-3-22 17:00:00";//Start exam time

echo $start_time."
";

$mm=60*60;//PHP time is calculated in seconds

echo date("Y-m-d H:i:s",strtotime($start_time) $mm);

If the output time is 8 hours different from the actual time (assuming the Beijing time zone is used), check the php.ini file and make the following settings: date.timezone = PRC

Recommended learning: php video tutorial

The above is the detailed content of How to format display time date function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete