Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculate time equivalent respective to a users time zone and a fixed time in PHP
    primarykey
    data
    text
    <p>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, <em>but not every day</em>.</p> <blockquote> <p>Our online sale begins at <strong>9am PDT</strong>. Your local time, based on your time zone setting, is <strong>September 11, 2012 - 12:02 am HST</strong>, which is UTC <strong>-10</strong> or <strong>3</strong> hours <strong>behind PDT</strong>. The sale will begin at <strong>XXam</strong> on local time.</p> </blockquote> <p>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.</p> <p>I have most of the variables calculated. I'm stuck on this part (The sale will begin at <strong>XXam</strong> 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 <em>same day</em> or the <em>next day</em> 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.</p> <p>"XX" should be 6:00 am in the example above.</p> <p>PHP Version 5.3.14</p> <pre><code>&lt;?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-&gt;setTimeZone(new DateTimeZone($_SESSION['user_tz'])); $user_tz_dst = $dateTime-&gt;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 &lt; TZ_OFFSET) { $behind_or_ahead = 'behind'; } else { $behind_or_ahead = 'ahead of'; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload