Jump to content

Timezone Adjustment


wintallo

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.