How to format display time date function in PHP

醉折花枝作酒筹
Release: 2023-03-09 21:58:02
forward
2686 people have browsed it

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

Copy after login

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

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!

Related labels:
php
source:csdn.net
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
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!