Home > Backend Development > PHP Tutorial > How to get the current time function in PHP

How to get the current time function in PHP

巴扎黑
Release: 2023-03-03 11:46:01
Original
1246 people have browsed it

PHP's method of obtaining the current time function

PHP's method of obtaining the current time function This article provides several functions of PHP to obtain the current time, date, time, etc., and also tells me how to solve the time zone problem. PHP tutorial to get the current time function article provides several PHP functions to get the current time, date, time, etc., and also tells me how to solve it.

php tutorial to get the current time function
This article shared by Brothers in PHP programming provides several functions of php to get the current time, date, time, etc., and also tells me how to solve the time zone problem.

Method 1 date function

echo date('y-m-d h:i:s',time());
//2010-08-29 11:25:26

Method 2 time function

$time = time ();

echo date("y-m-d",$time) //2016-08-15

Method 3 $_server['server_time']



Method 4 strftime

echo strftime ("%hh%m %a %d %b" ,time());

18h24 sunday 21 may
Another problem is the time zone issue. The default time difference of the PHP environment is 8 hours different from Beijing time. If we want to get the correct time, we must set it

Add date_default_timezone_set('prc');
or date.timezone=prc; in php.ini at the beginning of the php file.

Remember to restart apache after modifying php.ini

Related labels:
php
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