Table of Contents
PHP date("Y-m-d H:i:s");获取当前时间 差8小时解决办法
Home Backend Development PHP Tutorial PHP date("Y-m-d H:i:s");获取当前时间 差8小时解决方法(转)

PHP date("Y-m-d H:i:s");获取当前时间 差8小时解决方法(转)

Jun 13, 2016 am 11:00 AM
Asia date php

PHP date("Y-m-d H:i:s");获取当前时间 差8小时解决办法(转)

PHP date("Y-m-d H:i:s");获取当前时间 差8小时解决办法

(转)http://subin.org.cn/blog/post/430.html

原因:?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

??????? 从php5.1.0开始,php.ini里加了date.timezone这个选项,并且默认情况下是关闭的也就是显示的时间(无论用什么php命令)都是格林威治标准时间和我们的时间(北京时间)差了正好8个小时。

??????? 关于timezone 大陆内地可用的值是:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi ,PRC(依次为重庆,上海,乌鲁木齐,中华人民共和国)港台地区可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次为澳门,香港,台北)还有新加坡:Asia/Singapore其它:Etc/GMT-8 ,Singapore ,Hongkong

解决方法一:

??????? 再添加时间前 插入:CODE:(好像不用加)?date_default_timezone_set(PRC);

解决方法二:

??????? echo date("Y-m-d H:i:s",?time()+8*60*60);

解决方法三(修改php.ini文件):

??????? 找到php.ini中的“;date.timezone =”这行,将“;”去掉,改成“date.timezone = PRC”(PRC:People's Republic of China 中华人民共和国),重启Apache,问题解决。

?

附:date时间格式

date("Y-m-d H:i:s"); 显示的格式: 年-月-日 小时:分钟:秒

相关时间参数:

a - "am" 或是 "pm"?
A - "AM" 或是 "PM"?
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"?
D - 星期几,三个英文字母; 如: "Fri"?
F - 月份,英文全名; 如: "January"?
h - 12 小时制的小时; 如: "01" 至 "12"?
H - 24 小时制的小时; 如: "00" 至 "23"?
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"?
G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"?
i - 分钟; 如: "00" 至 "59"?
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"?
l - 星期几,英文全名; 如: "Friday"?
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"?
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"?
M - 月份,三个英文字母; 如: "Jan"?
s - 秒; 如: "00" 至 "59"?
S - 字尾加英文序数,二个英文字母; 如: "th","nd"?
t - 指定月份的天数; 如: "28" 至 "31"?
U - 总秒数?
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)?
Y - 年,四位数字; 如: "1999"?
y - 年,二位数字; 如: "99"?
z - 一年中的第几天; 如: "0" 至 "365"

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

See all articles