wintallo Posted February 13, 2008 Share Posted February 13, 2008 Hey, I want to get all times one my website to be outputted in the user's time zone, so I wrote a function that should make the proper adjustment. function output_date($timezone = 0, $time = -1) { if ( $time == -1 ) { $time = time(); } $adjustment = 60*60*(date('O', time())/100); $adjustment = $adjustment - (60*60*$timezone); return date('n/j/Y g:i:s A', $time+$adjustment); } The user's time zone is passed as the first parameter, and the time is passed as the second parameter, with the default of the current time. The function isn't working for me. The format of the timezone pass is as follows: -5 for GMT - 5, 0 for GMT, etc. Thanks! -wintallo Link to comment https://forums.phpfreaks.com/topic/90826-timezone-adjustment/ Share on other sites More sharing options...
wintallo Posted February 13, 2008 Author Share Posted February 13, 2008 Nevermind, I figured it out on my own. Here's the code for future reference function output_date($timezone = 0, $time = -1) { if ( $time == -1 ) { $time = time(); } $adjusted_time = $time; $adjustment = 60*60*(date('O', time())/100); $adjusted_time = $adjusted_time - $adjustment; $adjustment = 60*60*$timezone; $adjusted_time = $adjusted_time + $adjustment; return date('n/j/Y g:i:s A', $adjusted_time); } Search Engine Keywords: timezone, php, adjust, change, user, time zone, localize, local, calculate <solved> Link to comment https://forums.phpfreaks.com/topic/90826-timezone-adjustment/#findComment-465535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.