1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Time Script

Discussion in 'JavaScript' started by ledcomp, Jul 9, 2006.

  1. #1
    I am trying to write a Java script that will be in an html page. The script needs to tell us when it is 4:30 in different time zones so that we can make any last minute calls before they close. So at 1:30 it will tell us that 4:30 is coming up in New York so make your calls now.

    Thanks for your help in advance

    Dave
     
    ledcomp, Jul 9, 2006 IP
  2. uberpudge

    uberpudge Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I realize this post is a month old, but I only found this site this morning.

    The source below should get you pointed in the right direction.
    HTH
    Pete


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Time Sample</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    var t;

    function getCity(timezone)
    {
    var cities = new Array;

    cities[-12] = 'Baker Island';
    cities[-11] = 'American Samoa';
    cities[-10] = 'Honolulu';
    cities[-9] = 'Anchorage';
    cities[-8] = 'Los Angeles';
    cities[-7] = 'Denver';
    cities[-6] = 'Omaha';
    cities[-5] = 'New York';
    cities[-4] = 'Halifax';
    cities[-3] = 'Rio de Janeiro';
    cities[-2] = 'Fernando de Noronha';
    cities[-1] = 'Ponta Delgada';
    cities[-0] = 'London';
    cities[1] = 'Paris';
    cities[2] = 'Athens';
    cities[3] = 'Baghdad';
    cities[4] = 'Dubai';
    cities[5] = 'Karachi';
    cities[6] = 'Omsk';
    cities[7] = 'Jakarta';
    cities[8] = 'Perth';
    cities[9] = 'Tokyo';
    cities[10] = 'Melbourne';
    cities[11] = 'Guadalcanal';
    cities[12] = 'Wake Island';

    return cities[timezone];
    }

    function convertMinutesToHours(minutes)
    {
    return (minutes / 60);
    };

    function show430()
    {
    var now = new Date;
    var gmtOffset = 0;
    var targetTimeZone = 0;
    var p = document.getElementById('pTargetZone');

    //if(now.getMinutes() >= 30)
    //{
    gmtOffset = convertMinutesToHours(now.getTimezoneOffset());
    targetTimeZone = 16 - now.getHours() - gmtOffset;
    p.innerHTML = 'It is 4:' + now.getMinutes() + ':' + now.getSeconds() + ' PM in ' + getCity(targetTimeZone) + ' (' + targetTimeZone + ' GMT).';
    //}
    showZone();
    }

    function showZone()
    {
    t = setTimeout('show430()', 1000);
    }

    function stopUpdatingThatInfernalTime()
    {
    t = clearTimeout(t);
    }

    $(document).ready(showZone());
    </script>
    </head>
    <body>
    <div>
    <p id="pTargetZone"></p>
    <p><a href="javascript:stopUpdatingThatInfernalTime();">Stop updating that infernal time!</a></p>
    </div>
    </body>
    </html>
     
    uberpudge, Aug 10, 2010 IP