5.3以降、このis_dst
パラメーターはで非推奨になりましたmktime
。ただし、タイムスタンプには2つ前の時間が必要です。1つはdstあり、もう1つはdstなしです。
例:初回mktime("03","15","00","08","08","2008",1)
およびその他mktime("03","15","00","08","08","2008",0)
その問題を解決するのを手伝ってくれませんか。
私はGoogleでこの興味深い答えを見つけました:
/*
Since you're getting that error I'll assume you're using PHP 5.1 or
higher. UTC has no concept of DST, so what you really want to be using
are strtotime() and date_default_timezone_set(). Here's the idea:
*/
$someString = '10/16/2006 5:37 pm'; //this is a string
date_default_timezone_set('American/New_York'); //this is the user's timezone. It will determine how the string is turned into UTC
$timestamp = strtotime($someString); //$timestamp now has UTC equivalent of 10/16/2006 5:37 pm in New York
echo date('Y/m/d H:i:s', $timestamp); //prints out the nicely formatted version of that timestamp, as if you were in New York
date_default_timezone_set('American/Los_Angeles');
echo date('Y/m/d H:i:s', $timestamp); //prints out the nicely formatted version of that timestamp, as if you were in LA -- takes care of the conversion and everything
/*
So, setting the timezone then using strtotime() and date() takes care
of all the DST/non-DST stuff, converting between timezones, etc.
*/
ソースを表示します。
完全な答えではなく、私が考えることができるいくつかのアイデアです... DateTime :: format()メソッドは、DSTが有効であるかどうかを示すフォーマットコードを受け入れます。
$now = new DateTime;
$is_dst = $now->format('I')==1;
さて、DSTが逆だったとしたら何時になるかを知るためには、そのような変化がいつ起こるかを知る必要があります。このコード:
$time_zone = $now->getTimeZone();
var_dump( $time_zone->getTransitions(strtotime('2011-01-01'), strtotime('2011-12-31')) );
...プリント:
array(3) {
[0]=>
array(5) {
["ts"]=>
int(1293836400)
["time"]=>
string(24) "2010-12-31T23:00:00+0000"
["offset"]=>
int(3600)
["isdst"]=>
bool(false)
["abbr"]=>
string(3) "CET"
}
[1]=>
array(5) {
["ts"]=>
int(1301187600)
["time"]=>
string(24) "2011-03-27T01:00:00+0000"
["offset"]=>
int(7200)
["isdst"]=>
bool(true)
["abbr"]=>
string(4) "CEST"
}
[2]=>
array(5) {
["ts"]=>
int(1319936400)
["time"]=>
string(24) "2011-10-30T01:00:00+0000"
["offset"]=>
int(3600)
["isdst"]=>
bool(false)
["abbr"]=>
string(3) "CET"
}
}
日付が属する年の遷移を取得すると、isdstTRUEおよびisdstFALSEに応じてオフセットのリストを収集できます。適切なオフセットを選択すると、残りは簡単です。
$winter_offset = 3600;
$summer_offset = 7200;
$difference = $winter_offset-$summer_offset;
$winter = $now->modify( ($difference<0 ? '' : '+') . $difference . ' seconds');
echo $winter->format('H:i:s');