php用户的是林威治标准时间,所以与北京时间相关8小时,很多朋友在利用php date,time获取时间时都会发现相差有8个小时时差,下面我们来看解决办法。
最简单的办法如下
代码如下 | 复制代码 |
date_default_timezone_set("Etc/GMT+8");//这里比林威治标准时间慢8小时 ?> |
这样就解决了时差8小时的问题了
设置北京时区的方法:
代码如下 | 复制代码 |
date_default_timezone_set('PRC'); //设置中国时区 |
函数ini_set()设置时区:
可以在文件开头加入
代码如下 | 复制代码 |
ini_set('date.timezone','Asia/Shanghai'); // 'Asia/Shanghai' |
为上海时区
上面讲述的都是在php程序中来设置,但有的时间程序中是无效的,我下来看看在php.ini中操作方法
手动修改php.ini设置
打开php找到
代码如下 | 复制代码 |
date.timezone = "PRC" |
如有去掉前面的分号,没有的话手动添加!

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft