php5中date()得出的时间为什么不是当前时间的解决方法
相关设置是修改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');
?>
这样 时间相差八小时的问题就解决了!!~~~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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...

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.

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.

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

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.

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.

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...

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.
