Home Backend Development PHP Tutorial [转载]关于php时区时间异常有关问题

[转载]关于php时区时间异常有关问题

Jun 13, 2016 am 10:41 AM
date default etc

[转载]关于php时区时间错误问题

关于php时区时间错误问题??

http://czy4411741.blog.163.com/blog/static/342031272008123115233915/

从php5.1.0开始,php.ini里加入了date.timezone这个选项,默认情况下是关闭的

也就是显示的时间(无论用什么php命令)都是格林威治标准时间

和我们的时间(北京时间)差了正好8个小时,有以下3中方法可以恢复正常的时间。

1,最简单的方法就是不要用php5.1以上的版本

2,如果一定要用,而且不能修改php.ini,则需要在关于时间的初始化的语句的

上面加上 date_default_timezone_set (XXX);

cp无此问题

3,一劳永逸,仅限能修改php.ini。打开php.ini查找date.timezone 去掉前面的分号

= 后面加XXX,重启http服务(如apache2或iis等)即可

关于XXX,大陆内地可用的值是:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为重庆,上海,乌鲁木齐)

港台地区可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次为澳门,香港,台北)

还有新加坡:Asia/Singapore

老外好像把北京漏调了

其他可用的值是:Etc/GMT-8 ,Singapore ,Hongkong ,PRC

PRC是什么?PRC是中华人民共和国啊-_-

---------------------------------------------

解决方式:

在页头使用date_default_timezone_set()设置我的默认时区为北京时间

date_default_timezone_set('PRC');

echo date('Y-m-d H:i:s');

时间和服务器当前时间一样了!!祝贺之

?

附date_default_timezone_set用法如下

?

--------------------------------

date_default_timezone_set

(PHP 5 >= 5.1.0RC1)date_default_timezone_set -- 设定用于一个脚本中所有日期时间函数的默认时区

说明

bool date_default_timezone_set ( string timezone_identifier )

date_default_timezone_set() 设定用于所有日期时间函数的默认时区。

?

?

注: 自 PHP 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条 E_NOTICE 级别的错误信息。

?

参数

?

?

timezone_identifier

?

时区标识符,例如 UTC 或 Europe/Lisbon

?

返回值

本函数永远返回 TRUE(即使 timezone_identifier 参数不合法)。

------------------------------------------------------

再附上时区标识符:

CET

CST6CDT

Cuba

EET

Egypt

Eire

EST

EST5EDT

Etc/GMT

Etc/GMT+0

Etc/GMT+1

Etc/GMT+10

Etc/GMT+11

Etc/GMT+12

Etc/GMT+2

Etc/GMT+3

Etc/GMT+4

Etc/GMT+5

Etc/GMT+6

Etc/GMT+7

Etc/GMT+8

Etc/GMT+9

Etc/GMT-0

Etc/GMT-1

Etc/GMT-10

Etc/GMT-11

Etc/GMT-12

Etc/GMT-13

Etc/GMT-14

Etc/GMT-2

Etc/GMT-3

Etc/GMT-4

Etc/GMT-5

Etc/GMT-6

Etc/GMT-7

Etc/GMT-8

Etc/GMT-9

Etc/GMT0

Etc/Greenwich

Etc/UCT

Etc/Universal

Etc/UTC

Etc/Zulu

Factory

GB

GB-Eire

GMT

GMT+0

GMT-0

GMT0

Greenwich

Hongkong

HST

Iceland

Iran

Israel

Jamaica

Japan

Kwajalein

Libya

MET

MST

MST7MDT

Navajo

NZ

NZ-CHAT

Poland

Portugal

PRC

PST8PDT

ROC

ROK

Singapore

Turkey

UCT

Universal

UTC

W-SU

WET

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

PHP Warning: date() expects parameter 2 to be long, string given solution PHP Warning: date() expects parameter 2 to be long, string given solution Jun 22, 2023 pm 08:03 PM

When developing using PHP programs, you often encounter some warning or error messages. Among them, one error message that may appear is: PHPWarning:date()expectsparameter2tobelong,stringgiven. The error message means: the second parameter of the function date() is expected to be a long integer (long), but what is actually passed to it is a string (string). So, we

How to create and name a file/folder based on current timestamp How to create and name a file/folder based on current timestamp Apr 27, 2023 pm 11:07 PM

If you're looking for a way to automatically create and name files and folders based on system timestamps, you've come to the right place. There is a super simple way to accomplish this task. The created folders or files can then be used for various purposes such as storing file backups, sorting files based on date, etc. In this article, we will explain in some very simple steps how to automatically create files and folders in Windows 11/10 and name them according to the system’s timestamp. The method used is a batch script, which is very simple. Hope you enjoyed reading this article. Section 1: How to automatically create and name a folder based on the current timestamp of the system Step 1: First, navigate to the parent folder where you want to create the folder,

How to let all users print specified prompt information when logging in in Linux How to let all users print specified prompt information when logging in in Linux Feb 19, 2024 pm 05:12 PM

In Linux systems, through configuration files and scripts, you can display specified prompt information when all users log in. Next, we will introduce several commonly used implementation methods. Method 1: Modify the /etc/issue file. Open the terminal and use a text editor (such as vi or nano) to edit the /etc/issue file with root permissions. sudovi/etc/issue Add the prompt message you want to display at the end of the file, for example: Welcome to MyLinuxSystem! Please beaware that all activities are monitored. Save and close the file. Now when the user logs in, the system will display /

How to configure software mirror source in Ubuntu? How to configure software mirror source in Ubuntu? Feb 19, 2024 am 11:15 AM

Configuring software mirror sources is an effective way to increase download speeds and obtain software updates in Ubuntu. The following are the configuration steps: Open the terminal: On the Ubuntu desktop, press the Ctrl+Alt+T key combination to open the terminal. Back up the original software source configuration file (optional): If you want to keep the original software source configuration backup, you can execute the following command to back up the /etc/apt/sources.list file: sudocp/etc/apt/sources.list/ etc/apt/sources.list.backup Edit the software source configuration file: Use a text editor (such as nano or vi) to open the software source configuration file: sudonano

How to get the millisecond representation of a date using the getTime() method of the Date class How to get the millisecond representation of a date using the getTime() method of the Date class Jul 24, 2023 am 11:42 AM

How to get millisecond representation of date using getTime() method of Date class In Java, Date class is a class used to represent date and time. It provides many useful methods to manipulate and obtain information about date objects. Among them, the getTime() method is an important method in the Date class, which can return the millisecond representation of the date object. Next, we will detail how to use this method to obtain the millisecond representation of a date, and provide corresponding code examples. Using the Date class

Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Apr 21, 2023 pm 03:01 PM

1. Introduction The Date class in the java.util package represents a specific time, accurate to milliseconds. If we want to use our Date class, then we must introduce our Date class. Writing the year directly into the Date class will not produce the correct result. Because Date in Java is calculated from 1900, so as long as you fill in the first parameter with the number of years since 1900, you will get the year you want. The month needs to be subtracted by 1, and the day can be inserted directly. This method is rarely used, and the second method is commonly used. This method is to convert a string that conforms to a specific format, such as yyyy-MM-dd, into Date type data. First, define an object of Date type Date

Is ETC worth holding for the long term? Is ETC coin worth investing in? Is ETC worth holding for the long term? Is ETC coin worth investing in? Feb 27, 2024 pm 08:58 PM

Is ETC worth holding for the long term? ETC (Ethereum Classic) is a cryptocurrency based on blockchain technology. It was born on July 20, 2016. It is a branch of the Ethereum blockchain. The origin of ETC can be traced back to the controversy over the Ethereum hard fork in the Ethereum community. Is ETC coin worth investing in? Whether ETC coin is worth investing in requires comprehensive consideration of the following factors: Technical advantages: ETC coin is based on Ethereum blockchain technology, has advantages such as smart contracts and programmability, and has broad application prospects in the field of decentralized application development. Community support: ETC currency has an active community, and community members are confident in the long-term development of ETC currency. Market demand: ETC currency has a relatively high popularity in the cryptocurrency market.

What currency is ETC? What currency is ETC? Mar 01, 2024 am 11:30 AM

ETC coin, the full name of Ethereum Classic, is a cryptocurrency generated after the hard fork of the original Ethereum blockchain in 2016.

See all articles