Hello guys,

I need to grab times for few cities from world clock site. http://www.timeanddate.com/worldclock/

Not sure how I can do that.

So lets say I want to grab New York time from that site. Not the weekday name.. just New yorks time. and show it on my site.

How would I do that.

Any help would be appreciated

Thanks in advance

    it would be possible to actually fetch their website and extract the date information, but with php code you can actually do the same on your own.
    i made this code just now, i am in PST -0800 and it seemed to work fine for me. its not tested at all though so you may want to run some before using it. and note it doesn't handle dst, that'd have to be added but shouldn't be too hard.

    <?php
    
    $tz = date("Z");  //timezone offset of server in seconds
    
    $est  = 3600 * -5;  // -0500 gmt
    $cst  = 3600 * -6;
    $mst  = 3600 * -7;
    $pst  = 3600 * -8;
    $hast = 3600 * -10;
    
    // add (or subtract) the appropriate number of seconds from the offset to recalculate the time
    echo date("h:i A", strtotime("now +" . ($hast - $tz) . " seconds"));
    
    ?>
    

    also, check out the php manual pages on date stuff, there are quite a few comments with functions for doing this stuff. [man]gmdate[/man] has a few on it.

      You can simply use PHP's time zone support to determine the time in whatever location you like - read the docs for more details.

      It knows about most time zones, and understands daylight saving time (where it is used).

      Mark

        Write a Reply...