aximbigfan Posted August 17, 2009 Share Posted August 17, 2009 So I have these variables... $curtz // Timezone I want to convert to (example "-0600") $date['TZ'] // Timezone of the time I want to convert to $curtz (example "-0800") $date['D'] // Day (example "8") $date['M'] // Month (example "1") $date['Y'] // Year (example "2009") $date['H'] // Hour (example "23") $date['Min'] // Minute (example "59") $date['S'] //Second (example "59") And I have this horrible code... if ($curtz!=$date['TZ']) { $direction = substr($date['TZ'], 0, 1); $hours = substr($date['TZ'], 1, 2); if ($direction=='+') { $date['H'] = $date['H'] - $hours; if ($date['H']<0) { $date['H'] = $date['H'] + 23; $date['D']--; } } else { $date['H'] = $date['H'] + $hours; if ($date['H']>23) { $date['H'] = $date['H'] - 23; $date['D']++; } } $direction = substr($curtz, 0, 1); $hours = substr($curtz, 1, 2); if ($direction=='+') { $date['H'] = $date['H'] + $hours; if ($date['H']>23) { $date['H'] = $date['H'] - 23; $date['D']++; } } else { $date['H'] = $date['H'] - $hours; if ($date['H']<0) { $date['H'] = $date['H'] + 23; $date['D']--; } } if ($date['D']>$this->months[$date['M']][1]) { $date['M']++; if ($date['M']>12) { $date['M'] = 1; $date['Y']++; } $date['D'] = 1; } elseif ($date['D']<=0) { $date['M']--; if ($date['M']<=0) { $date['M'] = 12; $date['Y']--; } $date['D'] = $this->months[$date['M']][1]; } } Yes, I know, the above code is disgusting, and probably doesn't work right. Can anyone give me some pointers on how to fix this, or a better way of converting times between timezones? Thanks! Chris Link to comment https://forums.phpfreaks.com/topic/170575-best-way-to-convert-time-to-differnt-time-zone/ Share on other sites More sharing options...
Mardoxx Posted August 17, 2009 Share Posted August 17, 2009 doesn't php have a function to set time zone? Link to comment https://forums.phpfreaks.com/topic/170575-best-way-to-convert-time-to-differnt-time-zone/#findComment-899708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.