Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts

    Help With Timezones in Website Coding

    Greetings All

    Let me begin by saying I am quite new to development and this is my first website. I have learnt a bit of html and css which i have used for the site.
    I plan on trying to take on some more languages, to delevop my site further in the future, But would like any advice or feedback which could help me with this problem or point me in the right direction.

    Basically the issue is A part of my site has got a events schedule. The Problem has been the time for the events. i would like to set the time of each event to the Users timezone automatically. Below is basic code of what i have been using. which has been doing this using the scirpt in the "li class="time" but i need to change the scripts time for every event... The issue being to me

    1) Would this not load the script for each event? Slowing down the site loading?

    2)How could i possibly tweak the code to remove the script from the <li class="time"> and put it on the page to only load once. Then change it to ie. <li class="time">4:45pm</li> and that automatically changes to the users time from whats entered to there own Timezone from the script being loaded once on the page at the top of the page?

    <div class="programme">
                 <ul class="guides">
                    <a href="domain/xxxxx.php" class="guides" style="display : block; color: black; background-color: transparent;">
                        <li class="icon"><img src="images/event/????.png" alt="Schedule" width="26" height="27" class="icon"/></li>
                        <li class="time"><script>"src="http://www.thetimezoneconverter.com/js/ttzc.js"></script><script>new TTZC.Widget({  version:'inline',  t:'4:45 PM',tz:'London'}).display();</script></li>
                        <li class="game">Team A vs Team B</li>
                        <li class="location">Venue</li>
    If that doesnt seem possible, is there some where i can be pointed in to find out more or learn about what languages would be needed to be able to just write out the info in a database like this below which the website can pull down the info and place each variable in the correct place in the html code and css. Basically making it a bit more automated that the code is there and i just need to provide the info.

    Info(a href), Event Time Game Location
    xxxxx.php ????.png 06:00pm Team A vs Team B Field B
    yyyy.php ????.png 07:30pm Player A vs Player B Table 1
    zzzz.php ????.png 07:30pm Player A vs Player B Table 2
    hhhh.php ????.png 07:30pm Player A vs Player B Table 3

    Any help will be greatly appreciated, And being new to this any thing i dont understand in your replies i will try research more info on so i may provide you with the info or understand what you saying.

    Thank you
    Kind Regards

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,660 Times in 2,629 Posts
    You'll need a datastore, preferably a dbms.
    Timezones are simply handled by making use only of locale aware functionality, and both date procedural handling and datetime objects are locale aware.
    A simple example with the DateTime and DateTimezone:
    PHP Code:
    $dt = new DateTime('06:00pm', new DateTimeZone('UTC')); // personally I'd use 18:00 in a datastore, as pm would indicate a string.  Both should work though, but in a dbms you'd use a time datatype
    print $dt->format('F j Y H:i:s') . PHP_EOL;
    $dt->setTimezone(new DateTimeZone('America/Chicago'));
    $dt->format('F j Y H:i:s') . PHP_EOL
    Which, for today since we didn't give a date part ot the DateTime object, would result int:
    October 10 2013 18:00:00
    October 10 2013 13:00:00
    For the data you have here, a dbms would make the most sense. Query out what you need, and loop it. DateTime or just Time datatypes in mysql for example should be UTC stored, so when you fetch them you can simply give the timezone you want according to the timezone.

    Now getting the timezone is a whole different matter. You could probably use JS to store a cookie for that (which won't show until the *next* load of the page since that's how cookies work), or you could probably find a geoip webservice that may provide an actual timezone. If users signed up, that'd be trivial to add to one of their account preferences, but for guests, that's where the problem is. I'd probably give it to them in UTC, then let JS do the work. If they don't have JS or if its disabled, than they still get the time in UTC.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts