datetime - php - adjusting for timezones -
alright have code makes list of dates:
$dates = array(); for($i = 1; $i < 10; $i++) { $datetime = mktime(12, 0, 0, date('n'), date('j') + $i, date('y')); if(date('n', $datetime) != 6 && date('n', $datetime) != 7) { $dates[date('l, f js', $datetime)] = date('l, f js', $datetime); } }
the dates tomorrow , on long not saturday or sunday.
now problem "tomorrow" being changed @ 8:00 pm est.
to explain, it's wednesday. first option in list should thursday. however, once 8:00 pm est, first option friday. instead of changing @ 8:00 pm est i'd change @ 3:00 est (so on thursday @ 2:00 should still offer thursday choice)
i think getting time zones confused currently. 8pm edt = midnight utc.
anyway, in php 5.3:
$one_day = new dateinterval('p1d'); $tz = new datetimezone('america/new_york'); $start = new datetime('now', $tz); if ($start->format('g') >= 3) $start->add($one_day); foreach (new dateperiod($start, $one_day, 10) $date) { if ($date->format('n') < 6) echo $date->format('l, f js')."\n"; }
the logic remains same if on < 5.3, have things other functions strtotime()
, date()
, etc:
$one_day = 86400; date_default_timezone_set('america/new_york'); $start = time(); if (date('g', $start) >= 3) $start += $one_day; ($i = 0, $date = $start; $i < 10; ++$i, $date += $one_day) { if (date('n', $date) < 6) echo date('l, f js', $date)."\n"; }
i think should work.
Comments
Post a Comment