Home > Backend Development > PHP Tutorial > Get the current time function in php_PHP tutorial

Get the current time function in php_PHP tutorial

WBOY
Release: 2016-07-20 11:01:55
Original
1014 people have browsed it

The article "PHP Get Current Time Function" provides several functions of PHP to get 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
The article provides several PHP functions to obtain 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) //2010-08-29

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');
at the beginning of the php file Or date.timezone=prc; in php.ini.

Remember to restart apache after modifying php.ini

Please indicate the source when reprinting original tutorials on this site http://www.bkjia.com/phper/php.html


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445424.htmlTechArticlephp get current time function article provides several php functions to get the current time, date, time, etc. Also tell me how to solve the time zone problem. PHP tutorial to get the current time function...
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