国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial PHP的php.ini時區(qū)設(shè)置問題

PHP的php.ini時區(qū)設(shè)置問題

Jun 23, 2016 pm 02:29 PM

PHP的php.ini時區(qū)設(shè)置問題

2009-09-10 15:40

從php5.1.0開始,php.ini里加入了date.timezone這個選項,默認(rèn)情況下是關(guān)閉的,也就是顯示的時間(無論用什么php命令)都是格林威治標(biāo)準(zhǔn)時間,和我們的時間(北京時間)差了正好8個小時,有以下3中方法可以恢復(fù)正常的時間。
1、最簡單的方法就是不要用php5.1以上的版本;
2、如果要用5.1以上版本,而且不修改php.ini,則需要在關(guān)于時間的初始化的語句的上面加上date_default_timezone_set (XXX),或者使用date('Y-m-d G:i:T', strtotime('+8HOUR') )來獲取日期時間;
3,一勞永逸,僅限能修改php.ini。打開php.ini把date.timezone前面的分號去掉,在=后面加XXX,重啟http服務(wù)(如apache2或iis等)即可。
關(guān)于XXX,大陸內(nèi)地可用的值是:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi(依次為重慶,上海,烏魯木齊),港臺地區(qū)可用:Asia/Maca* ,Asia/Hong_Kong ,Asia/Taipei(依次為澳門,香港,臺北),還有新加坡:Asia/Singapore,以上沒有北京,不過接著往下看,其他可用的值是:Etc/GMT-8,Singapore ,Hongkong,PRC。PRC是什么?PRC是中華人民共和國?。。ㄟ@個就是北京時間吧)以上都是php官方說明檔里整理出來的GMT-8下面的地區(qū),可能會有遺漏,如有需要再上官方文檔里查看一下比較好:)

今天在PHP5下用date("H:i:s")時,發(fā)現(xiàn)參數(shù)"H"取出的時間與window下的時間不對。查了一下資料,發(fā)現(xiàn)是PHP5的php.ini里面默認(rèn)設(shè)置為:

[Date]
; Defines the default timezone used by the date functions
;date.timezone =

如此一來,按照默認(rèn)的時間便為GMT時間。而我們一般是使用北京時間,可以設(shè)置為:date.timezone = PRC或date.timezone = Asia/Shanghai。即:

[Date]
; Defines the default timezone used by the date functions
date.timezone = Asia/Shanghai

記得不要設(shè)置為"Asia/Beijing",老外好象對上海感興趣點,呵呵。

如果沒有權(quán)限改php.ini,可以用函數(shù)date_default_timezone_set('PRC');或date_default_timezone_set('Asia/Shanghai');

這個函數(shù)用于設(shè)定所有日期時間函數(shù)的默認(rèn)時區(qū)。手冊上如此說明:“自 PHP 5.1.0 起(此版本日期時間函數(shù)被重寫了),如果時區(qū)不合法則每個對日期時間函數(shù)的調(diào)用都會產(chǎn)生一條?E_NOTICE?級別的錯誤信息”。但是“本函數(shù)永遠(yuǎn)返回?TRUE(即使

在此再學(xué)習(xí)一下函數(shù):string

這個函數(shù)的返回值遵循以下順序:1:用?TZ?環(huán)境變量(如果非空)。3:date.timezone?配置選項(如果設(shè)定了的話)。4:自己推測(如果操作系統(tǒng)支持)。5:如果以上選擇都不成功,則返回

再深入學(xué)習(xí)一下什么是UTC:
協(xié)調(diào)世界時(UTC):?
一種稱為協(xié)調(diào)世界時的折衷時標(biāo)于1972年面世。為了確保協(xié)調(diào)世界時與世界時(UT1)相差不會超過0.9秒,有需要時便會在協(xié)調(diào)世界時內(nèi)加上正或負(fù)閏秒。因此協(xié)調(diào)世界時與國際原子時(TAI)之間會出現(xiàn)若干整數(shù)秒的差別。位于巴黎的國際地球自轉(zhuǎn)事務(wù)中央局(IERS)負(fù)責(zé)決定何時加入閏秒。

UTC = Coordinated Universal Time. 中文名稱為協(xié)調(diào)世界時.

GMT = Greenwich Mean Time. 中文名稱為格林尼治(平)時(這里的"w"是不發(fā)音的,而且"Green"要讀成"Gren")

UTC = GMT +/- 0.9 s?
因此 UTC 間中需要進(jìn)行 "閏秒" 以控制兩者相差。

?

php5.1x的時區(qū)問題導(dǎo)致相差八個小時!收藏
從php5.10開始,php中加入了時區(qū)的設(shè)置,在php中顯示的時間都是格林威治標(biāo)準(zhǔn)時間,這就造成了我們中國的用戶會差八個小時的問題!
相關(guān)設(shè)置是修改php.ini中的 date.timezone 參數(shù):
[Date]
; Defines the default timezone used by the date functions
;date.timezone =

默認(rèn)是關(guān)閉的,只需把注釋去掉,改為即可
[Date]
; Defines the default timezone used by the date functions
date.timezone = PRC

其中PRC是“中華人民共和國”!
其他選項可以參考php手冊。
不過這上面的亞洲地區(qū)漏掉了我們的首都北京,不知道老外是不是故意的!

如果沒有修改php.ini的權(quán)限,只需要在調(diào)用時間日期函數(shù)的時候,調(diào)用 date_default_timezone_set(’PRC’) 即可!
也可以調(diào)用date_default_timezone_get()來查看當(dāng)前的時區(qū)設(shè)置!

?於XXX,大??地可用的值是:
Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次?重?,上海,??木?)
港臺地?可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次?澳?,香港,臺北)
臺?地區(qū)可??:date.timezone = "Asia//Taipei"
?有新加坡:Asia/Singapore

本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/keenx/archive/2006/03/21/631432.aspx

摘自dedecms :php5 時區(qū)設(shè)置
if(PHP_VERSION > '5.1') {
$time51 = 'Etc/GMT'.($cfg_cli_time > 0 ? '-' : '+').abs($cfg_cli_time);
function_exists('date_default_timezone_set') ? @date_default_timezone_set($time51) : '';
}

如果php版本大于5.1執(zhí)行
$cfg_cli_time = -8;意思就是少8個小時!格式化后用data_default_timezone_set("Etc/GMT+8")設(shè)置!!
北京時區(qū)應(yīng)該是Etc/GMT+8

時區(qū)設(shè)置 一般都設(shè)置成+8個小時!
是格林威治標(biāo)準(zhǔn)時(GMT)
$date = gmdate("Y-m-d H:i:s",time()+8*3600)
只要滿足加8個小時就可以!寫成函數(shù)或者什么..就隨便了

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

How do I implement authentication and authorization in PHP? How do I implement authentication and authorization in PHP? Jun 20, 2025 am 01:03 AM

TosecurelyhandleauthenticationandauthorizationinPHP,followthesesteps:1.Alwayshashpasswordswithpassword_hash()andverifyusingpassword_verify(),usepreparedstatementstopreventSQLinjection,andstoreuserdatain$_SESSIONafterlogin.2.Implementrole-basedaccessc

How can you handle file uploads securely in PHP? How can you handle file uploads securely in PHP? Jun 19, 2025 am 01:05 AM

To safely handle file uploads in PHP, the core is to verify file types, rename files, and restrict permissions. 1. Use finfo_file() to check the real MIME type, and only specific types such as image/jpeg are allowed; 2. Use uniqid() to generate random file names and store them in non-Web root directory; 3. Limit file size through php.ini and HTML forms, and set directory permissions to 0755; 4. Use ClamAV to scan malware to enhance security. These steps effectively prevent security vulnerabilities and ensure that the file upload process is safe and reliable.

What are the differences between == (loose comparison) and === (strict comparison) in PHP? What are the differences between == (loose comparison) and === (strict comparison) in PHP? Jun 19, 2025 am 01:07 AM

In PHP, the main difference between == and == is the strictness of type checking. ==Type conversion will be performed before comparison, for example, 5=="5" returns true, and ===Request that the value and type are the same before true will be returned, for example, 5==="5" returns false. In usage scenarios, === is more secure and should be used first, and == is only used when type conversion is required.

How do I perform arithmetic operations in PHP ( , -, *, /, %)? How do I perform arithmetic operations in PHP ( , -, *, /, %)? Jun 19, 2025 pm 05:13 PM

The methods of using basic mathematical operations in PHP are as follows: 1. Addition signs support integers and floating-point numbers, and can also be used for variables. String numbers will be automatically converted but not recommended to dependencies; 2. Subtraction signs use - signs, variables are the same, and type conversion is also applicable; 3. Multiplication signs use * signs, which are suitable for numbers and similar strings; 4. Division uses / signs, which need to avoid dividing by zero, and note that the result may be floating-point numbers; 5. Taking the modulus signs can be used to judge odd and even numbers, and when processing negative numbers, the remainder signs are consistent with the dividend. The key to using these operators correctly is to ensure that the data types are clear and the boundary situation is handled well.

How can you interact with NoSQL databases (e.g., MongoDB, Redis) from PHP? How can you interact with NoSQL databases (e.g., MongoDB, Redis) from PHP? Jun 19, 2025 am 01:07 AM

Yes, PHP can interact with NoSQL databases like MongoDB and Redis through specific extensions or libraries. First, use the MongoDBPHP driver (installed through PECL or Composer) to create client instances and operate databases and collections, supporting insertion, query, aggregation and other operations; second, use the Predis library or phpredis extension to connect to Redis, perform key-value settings and acquisitions, and recommend phpredis for high-performance scenarios, while Predis is convenient for rapid deployment; both are suitable for production environments and are well-documented.

How do I stay up-to-date with the latest PHP developments and best practices? How do I stay up-to-date with the latest PHP developments and best practices? Jun 23, 2025 am 12:56 AM

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

What is PHP, and why is it used for web development? What is PHP, and why is it used for web development? Jun 23, 2025 am 12:55 AM

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

How to set PHP time zone? How to set PHP time zone? Jun 25, 2025 am 01:00 AM

TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

See all articles