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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.