Home php教程 php手册 php5中date()得出的时间为什么不是当前时间的解决方法

php5中date()得出的时间为什么不是当前时间的解决方法

Jun 13, 2016 pm 12:27 PM
date php.ini php5 no Why Revise method hour time yes of Related solve set up

相关设置是修改php.ini中的 date.timezone 参数:
[Date]
; Defines the default timezone used by the date functions
;date.timezone =

默认是关闭的,只需把注释去掉,改为即可
[Date]
; Defines the default timezone used by the date functions
date.timezone = PRC

其中PRC是“中华人民共和国”!
其他选项可以参考php手册。
不过这上面的亚洲地区漏掉了我们的首都北京,不知道老外是不是故意的!

如果没有修改php.ini的权限,只需要在调用时间日期函数的时候,调用 date_default_timezone_set('
PRC') 即可!
也可以调用date_default_timezone_get()来查看当前的时区设置!



關於XXX,大陸內地可用的值是:
Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次為重慶,上海,烏魯木齊)
港台地區可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次為澳門,香港,台北)
台灣地区可設為:date.timezone = "Asia//Taipei"
還有新加坡:Asia/Singapore


PHP5中的时间相差八小时的解决办法


安装好php5后,在论坛不经意间,在论坛上看到有人说php5.1.2的时间显示整整少8个小时,
    echo date("Y-m-d H:i:s");
?>
结果自己测试果然是相差8小时。

   后来经过在论坛上找资料,结果终于解决,在php5以及起以上的版本,要输出本地的时间(限中国)
,可以这么写代码:
   date_default_timezone_set('Asia/Shanghai');
   echo date('Y-m-d H:i:s');
?>

也可以这样写代码:
   date_default_timezone_set('Asia/Chongqing');
   echo date('Y-m-d H:i:s');
?>

这样 时间相差八小时的问题就解决了!!~~~

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

Does H5 page production require continuous maintenance? Does H5 page production require continuous maintenance? Apr 05, 2025 pm 11:27 PM

The H5 page needs to be maintained continuously, because of factors such as code vulnerabilities, browser compatibility, performance optimization, security updates and user experience improvements. Effective maintenance methods include establishing a complete testing system, using version control tools, regularly monitoring page performance, collecting user feedback and formulating maintenance plans.

Can JS run without H5? Can JS run without H5? Apr 06, 2025 am 09:06 AM

Is JavaScript available to run without HTML5? The JavaScript engine itself can run independently. Running JavaScript in a browser environment depends on HTML5 because it provides the standardized environment required to load and execute code. The APIs and features provided by HTML5 are crucial to modern JavaScript frameworks and libraries. Without HTML5 environments, many JavaScript features are difficult to implement or cannot be implemented.

Why can custom style sheets take effect on local web pages in Safari but not on Baidu pages? Why can custom style sheets take effect on local web pages in Safari but not on Baidu pages? Apr 05, 2025 pm 05:15 PM

Discussion on using custom stylesheets in Safari Today we will discuss a custom stylesheet application problem for Safari browser. Front-end novice...

What are the advantages of H5 page production What are the advantages of H5 page production Apr 05, 2025 pm 11:48 PM

The advantages of H5 page production include: lightweight experience, fast loading speed, and improving user retention. Cross-platform compatibility, no need to adapt to different platforms, improving development efficiency. Flexibility and dynamic updates, no audit required, making it easier to modify and update content. Cost-effective, lower development costs than native apps.

Unable to log in to mysql as root Unable to log in to mysql as root Apr 08, 2025 pm 04:54 PM

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

Why does a specific div element in the Edge browser not display? How to solve this problem? Why does a specific div element in the Edge browser not display? How to solve this problem? Apr 05, 2025 pm 08:21 PM

How to solve the display problem caused by user agent style sheets? When using the Edge browser, a div element in the project cannot be displayed. After checking, I posted...

The relationship between Bootstrap Table garbled and page encoding The relationship between Bootstrap Table garbled and page encoding Apr 07, 2025 pm 12:03 PM

Bootstrap Table garbled is usually because the page encoding is inconsistent with the table data encoding. To solve this problem, you need to make sure they are consistent. The specific steps include: checking page and table data encoding, setting page encoding, and verifying the encoding. If UTF-8 is used, the server should also support it. If it cannot be resolved, try using the JavaScript encoding library.

See all articles