Home > Backend Development > PHP Problem > How to set local time in php

How to set local time in php

藏色散人
Release: 2023-03-13 17:00:01
Original
2724 people have browsed it

How to set local time in php: 1. Use "date_default_timezone_set()" in the header to set the default time zone to Beijing time; 2. Set the value of "date.timezone" in php.ini to PRC. .

How to set local time in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php How to set the local time?

php time is set to local

PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in D:\PHPWEB\news\file.php on line 17 。
Copy after login

This is because the time taken by PHP is Greenwich Mean Time, so there will be a difference between your local time and Greenwich Mean Time It is about 8 hours different from Beijing time. We can solve it according to the following method:

1. Use date_default_timezone_set() on the header of the page to set the default time zone to Beijing time, that is, That’s it.

2. Set the value of date.timezone in php.ini to PRC. After setting it, it will be: date.timezone=PRC. At the same time, uncomment this line of code, that is, remove the preceding semicolon. .

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set local time in php. For more information, please follow other related articles on the PHP Chinese website!

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