The thing that you want to do is not practical and will lead to your users hating you.
The entire reason behind the named time zones is to accurately represent local time. Representing "Standard" time as a local time when that local area is inside DST is objectively incorrect. Anyone inside that time zone that reads the time is going to be misinformed.
If you need to store and work with dates and times that ignore time zones, then use UTC for that purpose, i.e. storage and normal math. It's worth remembering that even the good old Unix timestamp is "seconds past midnight, January 1, 1970, UTC".
If you need to represent times local to the user, then you should allow them to pick their local time zone, and convert it on display. Modern PHP's DateTime and DateTimeZone make this dead-simple. From the interactive prompt:
php > $utc = new DateTimeZone('UTC');
php > $amla = new DateTimeZone('America/Los_Angeles');
php >
php > $two_past_midnight = new DateTime('2011-04-05 00:02', $utc);
php > $two_past_midnight->setTimeZone($amla);
php > echo $two_past_midnight->format('Y-m-d H:i:s');
2011-04-04 17:02:00
No mess, no fuss. It took care of the math for us when we switched the time zone.
In the alternative, if you really, really, really want to flatten out DST timezones, look at getTransitions
and getOffset
in combination with the various timezone date()
formats, I
in particular. You can poke and prod at the resulting information to find when the "standard" version of any DST zone next transitions and adjust it accordingly. Remember that different areas transition at different times, and not all areas transition by the same amount ... and some don't transition at all. I think someone mentioned Indiana already.
Normally I'd also provide sample code here, but date math fills me with an insatiable thirst for violence. Whoever decided that 60, 60, 24, 7, 4-6, 12 and 52 were acceptable ways to think about times and dates were evil, evil people. Thankfully they've all been dead for between hundreds and thousands of years.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…