Formatting a date string to unix timestamp through strtotime() will result in a date that completely ingnores the set timezone. If you're pulling mysql dates from database then use the unix_timestamp() function within the query and you won't have any problems.
date_default_timezone_set
(PHP 5 >= 5.1.0)
date_default_timezone_set — 设定用于一个脚本中所有日期时间函数的默认时区
说明
bool date_default_timezone_set
( string $timezone_identifier
)
date_default_timezone_set() 设定用于所有日期时间函数的默认时区。
Note: 自 PHP 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条 E_NOTICE 级别的错误信息,如果使用系统设定或 TZ 环境变量则还会产生 E_STRICT 级别的信息。
返回值
如果 timezone_identifier 参数无效则返回 FALSE,否则返回 TRUE。
更新日志
| 版本 | 说明 |
|---|---|
| 5.1.2 | 本版本开始验证 timezone_identifier 参数。 |
date_default_timezone_set
dan a+t vespernet.co.uk
08-Feb-2008 12:49
08-Feb-2008 12:49
Anonymous
21-Jan-2008 05:01
21-Jan-2008 05:01
<?php
/**
* @Author H22CREATIONS
* @Copyright 2008
*/
/***************************
* array get_time_byTZ([ integer $gmt_plus])
****************************/
function get_time_byTZ($gmt_plus=0){//must be in [-12..12]
//GET Difference between Server TZ and desired TZ
$sec_diff=date('Z')-($gmt_plus*3600);
//Return $gmt_plus as a string
if ($gmt_plus>=0) $gmt_plus='+'.$gmt_plus;
//Think about it!
$time=strtotime($sec_diff=(($sec_diff<=0)?'+':'-').abs($sec_diff).' seconds');
return array($time,$gmt_plus,$sec_diff/3600);
}
//Test
list($time,$gmt_plus,$tz_diffrence)=get_time_byTZ(-1);
echo date('m/d/y G:i:s ',$time).$gmt_plus;
?>
php_manual at lk2 dot de
13-Aug-2007 04:37
13-Aug-2007 04:37
@davidn at datalinktech dot com dot au
set_default_timezone() has no effect at all on how apache logs are timestamped (at least for me)
It is however true, that all dates and times that php formats that are _not_ timestamps will be in that timezone.
Timestamps are always GMT
legolas558 d0t users dot sf dot net
10-Jun-2007 09:34
10-Jun-2007 09:34
http://drakecms.sf.net/index.php?option=content&id=32&Itemid=10
A short tutorial which explains how to consistently implement timezones with PHP4 while remaining forward compatible with PHP5.
PeerGoal.com
12-Feb-2007 08:21
12-Feb-2007 08:21
The problem:
date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PST/-8.0/no DST' instead
Of course this is a problem that recently surfaced since PHP5. Quick fix is to set your time zone, add this line to your php code:
date_default_timezone_set("America/Los_Angeles");
davidn at datalinktech dot com dot au
22-Dec-2006 09:27
22-Dec-2006 09:27
Note that there may be some unexpected side-effects that result from using either set_default_timezone() or the putenv("TZ=...") workalike for earlier PHP versions. ANY date formatted and output either by PHP or its apache host process will be unconditionally expressed in that timezone.
This does indeed include the web server's logs and other output files and reports which by default usually do not include any indication of timezone. This has a further side-effect on log processing and analysis, obviously.
Chris
23-Nov-2006 02:14
23-Nov-2006 02:14
See the user contributed notes for the putenv function for a workaround for previous versions of PHP.
