-
-
Save 1stevengrant/3969207 to your computer and use it in GitHub Desktop.
var $dateTime = new DateTime(); | |
$dateTime->setTimezone(new DateTimeZone('America/New_york')); | |
$dateTime->setTimestamp(time()); | |
$isDst = (bool)$dateTime->format('I') ? "y" : "n"; | |
$conf['daylight_savings'] = $isDst; |
I can't take any credit for this - thanks go to @lowellkitchen for this
If you have control over the server time, and/or the server time is set to what you want (e.g., server timezone set to the same timezone that you want for the website) you can do it in one line:
$config['daylight_savings'] = date('I') ? 'y' : 'n';
@gregferrell Do you have a reference for this being 5.3 only? All I could find is the DateTime class being 5.2+
@adrianmacneil the setTimestamp method was added in PHP 5.3: http://www.php.net/manual/en/datetime.settimestamp.php
their are easy work arounds to this for folks not on PHP 5.3 yet.
Also set, this recently hosed me.
$config['default_site_dst'] = date('I') ? 'y' : 'n';
And you might have to do something like this for your old entries when going from UM6 (CDT) to UM5 (CST) and using "fixed" dates (field_id is 394).
update exp_channel_data SET field_dt_394 = 'UM5';
Or switch everything to localized using (field_id is 394).
update exp_channel_data SET field_dt_394 = '';
PHP 5.2 version:
$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/Chicago'));
$date = getdate();
$dateTime->setDate($date['year'], $date['mon'], $date['mday']);
$dateTime->setTime($date['hours'], $date['minutes'], $date['seconds']);
$conf['daylight_savings'] = $dateTime->format('I') ? 'y' : 'n';
America/New_york
should be America/New_York
, no? http://www.php.net/manual/en/timezones.america.php
My website is having a countdown from 23july to current time.I am from india and my timing lag 5.30 hours.The problem is the site is also for pakistan,srilanka,bangladesh.So i need to have respective timezone using php.Any idea?Currently the countdown get deprecated by one day at 5.30 in morning instead of midnight
http://www.tensports.com/event/other/commonwealth-games-2014
Great workaround. (Note this is PHP 5.3+ only, but most hosts are using that now.)