Below is some text I am working on that tells users what time an online sale begins respective to their local time zone. The online sale always begins at 9am Pacific Time, but not every day.
Our online sale begins at 9am PDT. Your local time, based on your time zone setting, is September 11, 2012 - 12:02 am HST, which is UTC -10 or 3 hours behind PDT. The sale will begin at XXam on local time.
In the example above, the users time zone is Pacific/Honolulu and is stored in the db, and also set in a session called user_tz when they sign in.
I have most of the variables calculated. I'm stuck on this part (The sale will begin at XXam on local time.) ...which is how to determine the local time equivalent of 9am Pacific Time, and whether the local time equivalent will be the same day or the next day depending on how far ahead of Pacific Time they are. For example, Melbourne Australia, the sale would begin, the next day, September 12 at 2:00am since Melbourne is 17 hours ahead of Pacific Time.
"XX" should be 6:00 am in the example above.
PHP Version 5.3.14
<?php
// gets the users time zone offset in seconds from UTC
// shown above as -10
$user_tz_offset = getTimeZoneOffset($_SESSION['user_tz']);
// gets the dst code of the timezone ...example: pdt or pst
// shown above as HST
$dateTime = new DateTime();
$dateTime->setTimeZone(new DateTimeZone($_SESSION['user_tz']));
$user_tz_dst = $dateTime->format('T');
// gets the difference in hours from Pacific time to the users time zone
// shown above as 3
$hours_diff = abs(($user_tz_offset - TZ_OFFSET)/3600);
// gets the users local time
// shown above as September 11, 2012 - 12:02 am HST
$user_time_now = date("F j, Y \- g:i a", (time()+$user_tz_offset));
// add a plus sign to time zones that are not negative
if( !strstr( $user_tz_offset, "-" ))
{
$add_plus_sign = '+';
}
// determine whether we should say "ahead of" or "behind" respective to Pacific time
// TZ_OFFSET is a constant defined in config
if( $user_tz_offset < TZ_OFFSET)
{
$behind_or_ahead = 'behind';
}
else
{
$behind_or_ahead = 'ahead of';
}
?>