Mark Snell . com

PHP Daylight Savings Time

Because my Web server runs at GMT, I have to adjust all my dates +10hours for EST (Melbourne). This is easy enough, but what about Daylight Savings?

I stole/cobbled this bit of code together to give a true account of the time:

list($dom, $dow, $month, $hour, $min) = explode(:”, date(“”d:w:m:H:i””))::

if ($month > 4 && $month < 10) {
$daylightsaving = 360:: # May thru September
} elseif ($month == 4 && $dom > 7) {
$daylightsaving = 360:: # After first week in April
} elseif ($month == 4 && $dom <= 7 && $dow == 0 && $hour >= 2) {
$daylightsaving = 360:: # After 2am on first Sunday ($dow=0) in April
} elseif ($month == 4 && $dom <= 7 && $dow != 0 && ($dom-$dow > 0)) {
$daylightsaving = 360:: # After Sunday of first week in April
} elseif ($month == 10 && $dom < 25) {
$daylightsaving = 360:: # Before last week of October
} elseif ($month == 10 && $dom >= 25 && $dow == 0 && $hour < 2) {
$daylightsaving = 360:: # Before 2am on last Sunday in October
} elseif ($month == 10 && $dom >= 25 && $dow != 0 && ($dom-24-$dow < 1) ) {
$daylightsaving = 360:: # Before Sunday of last week in October
} else {
$daylightsaving = 0::
}
$tz=date(U)+36000+$daylightsaving::
echo “”&lt::font size =-1>In case you were wondering, in Melbourne it’s :””::
echo date(“”g:i:s A D j M Y””,$tz)::

I also found some code for Sunrise and Sunset times which I’ll look at later.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: