Time Zones

Discussion in 'Javascript' started by Gregc., Sep 23, 2006.

  1. Gregc.

    Gregc. Guest

    Hi

    Would anyone have an example of working out international time zones,
    using an array.

    Greg
    Gregc., Sep 23, 2006
    #1
    1. Advertising

  2. JRS: In article <>,
    dated Sat, 23 Sep 2006 01:55:47 remote, seen in
    news:comp.lang.javascript, Gregc. <> posted :

    >Would anyone have an example of working out international time zones,
    >using an array.


    A remarkably ambiguous question. Read
    <URL:http://www.merlyn.demon.co.uk/js-dates.htm> ff. (incl date5)
    and <URL:http://www.merlyn.demon.co.uk/misctime.htm> then reformulate.

    It's a good idea to read the newsgroup and its FAQ.
    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Sep 23, 2006
    #2
    1. Advertising

  3. Gregc.

    Gregc. Guest

    Dr John Stockton wrote:
    > A remarkably ambiguous question. Read
    > <URL:http://www.merlyn.demon.co.uk/js-dates.htm> ff. (incl date5)
    > and <URL:http://www.merlyn.demon.co.uk/misctime.htm> then reformulate.
    >
    > It's a good idea to read the newsgroup and its FAQ.
    > --
    > © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    > <URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
    > <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    > <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


    Thanks but already looked on your website.

    Greg
    Gregc., Sep 24, 2006
    #3
  4. JRS: In article <>,
    dated Sat, 23 Sep 2006 20:25:12 remote, seen in
    news:comp.lang.javascript, Gregc. <> posted :
    >
    >Dr John Stockton wrote:
    >> A remarkably ambiguous question. Read
    >> <URL:http://www.merlyn.demon.co.uk/js-dates.htm> ff. (incl date5)
    >> and <URL:http://www.merlyn.demon.co.uk/misctime.htm> then reformulate.
    >>
    >> It's a good idea to read the newsgroup and its FAQ.
    >> --
    >> © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    >> <URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
    >> <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    >> <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    >
    >Thanks but already looked on your website.


    Then you should know :-

    a) Not to quote signatures.

    b) Enough to ask an answerable question. Note that, as of about 18:20
    GMT today, no-one shows any sign of understanding which meaning your
    question might have been intended to have. You've not even indicated
    your location, so we don't know whether US zones are to be included.


    --
    © John Stockton, Surrey, UK. REPLYyyww merlyn demon co uk Turnpike 4 ©
    Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
    Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
    No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
    Dr John Stockton, Sep 24, 2006
    #4
  5. Gregc.

    RobG Guest

    Gregc. wrote:
    > Dr John Stockton wrote:
    > > A remarkably ambiguous question. Read
    > > <URL:http://www.merlyn.demon.co.uk/js-dates.htm> ff. (incl date5)
    > > and <URL:http://www.merlyn.demon.co.uk/misctime.htm> then reformulate.

    [...]
    > Thanks but already looked on your website.
    >


    As John said, you need to supply a bit more information in your
    question - most people won't waste time guessing possible answers to
    something so vague, or to ask questions trying to find out what it is
    that you want. So...

    What do you want to do - send out a date and time that will be
    displayed in a users' local timezone? Let the user input dates and
    times and convert them to your server's local time? Convert solar time
    to astronomical time?

    The general strategy is to convert stuff to UTC and then turn it into
    whatever local time as appropriate - usually just for display. But
    that may not suit or be required in your case. More information is
    required.


    --
    Rob
    RobG, Sep 25, 2006
    #5
  6. Gregc.

    Gregc. Guest

    RobG wrote:
    > As John said, you need to supply a bit more information in your
    > question - most people won't waste time guessing possible answers to
    > something so vague, or to ask questions trying to find out what it is
    > that you want. So...
    >
    > What do you want to do - send out a date and time that will be
    > displayed in a users' local timezone? Let the user input dates and
    > times and convert them to your server's local time? Convert solar time
    > to astronomical time?
    >
    > The general strategy is to convert stuff to UTC and then turn it into
    > whatever local time as appropriate - usually just for display. But
    > that may not suit or be required in your case. More information is
    > required.
    >
    >
    > --



    Okay, well this is what I am trying to do:

    HTML>
    <HEAD>
    <SCRIPT LANGUAGE=javascript type="text/javascript">

    var selectedCity;
    var timeDiff;
    var arrTimeZones = new Array();
    arrTimeZones [0] = "Paris;+;1;;"
    arrTimeZones [1] = "London;+;0;;"
    arrTimeZones [2] = "Rome;+;1;;"
    arrTimeZones [3] = "New York City;-;5;;"
    arrTimeZones [4] = "Toronto;-;5;;"
    arrTimeZones [5] = "Sydney;+;10;;"
    arrTimeZones [6] = "Moscow;+;3;;"
    arrTimeZones [7] = "Tokyo;+;9;;"
    arrTimeZones [8] = "Beijing;+;8;;"
    arrTimeZones [9] = "San Francisco;-;8;;"
    arrTimeZones [10] = "Cairo;+;2;;"
    arrTimeZones [11] = "Bangkok;+;7;;"
    arrTimeZones [12] = "Lima;-;5;;"


    function window_onload() {
    updateTimeZone();
    window.setInterval("updateTimeZone()", 1000);
    }
    function updateTimeZone()
    {
    var lstCity = document.form1.lstCity;
    timeDiff = lstCity.options[lstCity.selectedIndex].value;
    selectedCity = lstCity.options[lstCity.selectedIndex].text;
    updateTime();




    }
    function getTimeString(dateObject)
    {
    var timeString;
    var hours = dateObject.getHours();
    if (hours < 10)
    hours = "0" + hours;
    var minutes = dateObject.getMinutes();
    if (minutes < 10)
    minutes = "0" + minutes;

    var seconds = dateObject.getSeconds()
    if (seconds < 10)
    seconds = "0" + seconds;
    timeString = hours + ":" + minutes + ":" + seconds;
    return timeString;
    }
    function updateTime()
    {
    var nowTime = new Date();
    var resultsFrame = window.top.resultsFrame.document;
    resultsFrame.open()
    resultsFrame.write("Local Time is " + getTimeString(nowTime) +
    "<BR>");
    nowTime.setMinutes(nowTime.getMinutes() +
    nowTime.getTimezoneOffset() +
    parseInt(timeDiff));
    resultsFrame.write(selectedCity + " time is " +
    getTimeString(nowTime));
    resultsFrame.close();
    }

    </SCRIPT>
    </HEAD>
    <BODY LANGUAGE=JavaScript onload="window_onload()">
    <FORM NAME=form1>
    <SELECT SIZE=5 NAME=lstCity LANGUAGE=JavaScript
    onchange="updateTimeZone(this);">

    <option>Paris</option>
    <option>London</option>
    <option>Rome</option>
    <option>New York</option>
    <option>Toronto</option>
    <option>Sydney</option>
    <option>Moscow</option>
    <option>Tokyo</option>
    <option>Beijing</option>
    <option>San Francisco</option>
    <option>Cairo</option>
    <option>Bangkok</option>
    <option>Lima</option>

    </select>
    </td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>

    But I am having trouble trying to get it to work. Would anyone have an
    idea?

    Greg
    Gregc., Sep 25, 2006
    #6
  7. JRS: In article <>,
    dated Mon, 25 Sep 2006 00:30:53 remote, seen in
    news:comp.lang.javascript, Gregc. <> posted :
    >
    >
    >Okay, well this is what I am trying to do:
    >
    >HTML>
    ><HEAD>
    ><SCRIPT LANGUAGE=javascript type="text/javascript">

    ^^^^^^^^^^^^^^^^^^^ deprecated, superfluous.
    >
    >var selectedCity;
    >var timeDiff;
    >var arrTimeZones = new Array();
    >arrTimeZones [0] = "Paris;+;1;;"
    >arrTimeZones [1] = "London;+;0;;"
    >arrTimeZones [2] = "Rome;+;1;;"
    >arrTimeZones [3] = "New York City;-;5;;"
    >arrTimeZones [4] = "Toronto;-;5;;"
    >arrTimeZones [5] = "Sydney;+;10;;"
    >arrTimeZones [6] = "Moscow;+;3;;"
    >arrTimeZones [7] = "Tokyo;+;9;;"
    >arrTimeZones [8] = "Beijing;+;8;;"
    >arrTimeZones [9] = "San Francisco;-;8;;"
    >arrTimeZones [10] = "Cairo;+;2;;"
    >arrTimeZones [11] = "Bangkok;+;7;;"
    >arrTimeZones [12] = "Lima;-;5;;"


    var arrTimeZones = ["Paris;+;1;;", ..., "Lima;-;5;;"]
    is simpler.

    >function window_onload() {
    > updateTimeZone();
    > window.setInterval("updateTimeZone()", 1000);
    >}


    Be aware that setInterval(..., 1000) will not fire synchronously with
    the seconds of the displaying computer.

    >function updateTimeZone()
    >{
    > var lstCity = document.form1.lstCity;
    > timeDiff = lstCity.options[lstCity.selectedIndex].value;
    > selectedCity = lstCity.options[lstCity.selectedIndex].text;
    > updateTime();
    >
    >
    >
    >
    >}
    >function getTimeString(dateObject)
    >{
    > var timeString;
    > var hours = dateObject.getHours();
    > if (hours < 10)
    > hours = "0" + hours;
    > var minutes = dateObject.getMinutes();
    > if (minutes < 10)
    > minutes = "0" + minutes;
    >
    > var seconds = dateObject.getSeconds()
    > if (seconds < 10)
    > seconds = "0" + seconds;
    > timeString = hours + ":" + minutes + ":" + seconds;
    > return timeString;
    >}


    Don't repeat code; use a (one-line) Leading Zero function.

    >function updateTime()
    >{
    > var nowTime = new Date();
    > var resultsFrame = window.top.resultsFrame.document;
    > resultsFrame.open()
    > resultsFrame.write("Local Time is " + getTimeString(nowTime) +
    >"<BR>");
    > nowTime.setMinutes(nowTime.getMinutes() +
    >nowTime.getTimezoneOffset() +
    > parseInt(timeDiff));


    There should be no need to use parseInt; and used thus it will probably
    give incorrect results for differences of 08 & 09. Use unary +.

    alert(timeDiff) shows me an empty string.

    > resultsFrame.write(selectedCity + " time is " +
    >getTimeString(nowTime));
    > resultsFrame.close();
    >}
    >
    ></SCRIPT>
    ></HEAD>
    ><BODY LANGUAGE=JavaScript onload="window_onload()">
    ><FORM NAME=form1>
    ><SELECT SIZE=5 NAME=lstCity LANGUAGE=JavaScript
    >onchange="updateTimeZone(this);">
    >
    > <option>Paris</option>
    >
    ><option>London</option>
    > <option>Rome</option>
    > <option>New
    >York</option>
    >
    ><option>Toronto</option>
    >
    ><option>Sydney</option>
    >
    ><option>Moscow</option>
    > <option>Tokyo</option>
    >
    ><option>Beijing</option>
    > <option>San
    >Francisco</option>
    > <option>Cairo</option>
    >
    ><option>Bangkok</option>
    > <option>Lima</option>
    >
    > </select>
    > </td>
    > </tr>
    > </table>
    > </form>
    > </td>
    > </tr>
    ></table>
    ></body>
    ></html>
    >
    >But I am having trouble trying to get it to work. Would anyone have an
    >idea?


    Explain what trouble. For me, it fails since window.top.resultsFrame.
    document is not an Object; don't presume that everyone sees the same.
    Maybe you need to understand the use of "open". You could instead write
    to a TextArea, for simplicity.

    ISTM that timeDiff is an empty string when in updateTime.

    You need to learn how to debug code. Write in smaller pieces, testing
    as you go. Function alert() will show the value of a variable.

    I see no allowance for the Summer Time rules of each location.

    If this is coursework, consider a different career.

    If it represents a practical need, then js-date5.htm#Demo serves for any
    location (even LHI <g>) and js-date5.htm#SLGD (was SLHD) serves for a
    list of locations. While the latter input is a TextArea, the value is
    immediately converted to an Array.

    It's a good idea to read the newsgroup and its FAQ.
    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Sep 25, 2006
    #7
  8. Gregc.

    Gregc. Guest

    Dr John Stockton wrote:
    > JRS: In article <>,
    > dated Mon, 25 Sep 2006 00:30:53 remote, seen in
    > news:comp.lang.javascript, Gregc. <> posted :
    > >
    > >
    > >Okay, well this is what I am trying to do:
    > >
    > >HTML>
    > ><HEAD>
    > ><SCRIPT LANGUAGE=javascript type="text/javascript">

    > ^^^^^^^^^^^^^^^^^^^ deprecated, superfluous.
    > >
    > >var selectedCity;
    > >var timeDiff;
    > >var arrTimeZones = new Array();
    > >arrTimeZones [0] = "Paris;+;1;;"
    > >arrTimeZones [1] = "London;+;0;;"
    > >arrTimeZones [2] = "Rome;+;1;;"
    > >arrTimeZones [3] = "New York City;-;5;;"
    > >arrTimeZones [4] = "Toronto;-;5;;"
    > >arrTimeZones [5] = "Sydney;+;10;;"
    > >arrTimeZones [6] = "Moscow;+;3;;"
    > >arrTimeZones [7] = "Tokyo;+;9;;"
    > >arrTimeZones [8] = "Beijing;+;8;;"
    > >arrTimeZones [9] = "San Francisco;-;8;;"
    > >arrTimeZones [10] = "Cairo;+;2;;"
    > >arrTimeZones [11] = "Bangkok;+;7;;"
    > >arrTimeZones [12] = "Lima;-;5;;"

    >
    > var arrTimeZones = ["Paris;+;1;;", ..., "Lima;-;5;;"]
    > is simpler.
    >
    > >function window_onload() {
    > > updateTimeZone();
    > > window.setInterval("updateTimeZone()", 1000);
    > >}

    >
    > Be aware that setInterval(..., 1000) will not fire synchronously with
    > the seconds of the displaying computer.
    >
    > >function updateTimeZone()
    > >{
    > > var lstCity = document.form1.lstCity;
    > > timeDiff = lstCity.options[lstCity.selectedIndex].value;
    > > selectedCity = lstCity.options[lstCity.selectedIndex].text;
    > > updateTime();
    > >
    > >
    > >
    > >
    > >}
    > >function getTimeString(dateObject)
    > >{
    > > var timeString;
    > > var hours = dateObject.getHours();
    > > if (hours < 10)
    > > hours = "0" + hours;
    > > var minutes = dateObject.getMinutes();
    > > if (minutes < 10)
    > > minutes = "0" + minutes;
    > >
    > > var seconds = dateObject.getSeconds()
    > > if (seconds < 10)
    > > seconds = "0" + seconds;
    > > timeString = hours + ":" + minutes + ":" + seconds;
    > > return timeString;
    > >}

    >
    > Don't repeat code; use a (one-line) Leading Zero function.
    >
    > >function updateTime()
    > >{
    > > var nowTime = new Date();
    > > var resultsFrame = window.top.resultsFrame.document;
    > > resultsFrame.open()
    > > resultsFrame.write("Local Time is " + getTimeString(nowTime) +
    > >"<BR>");
    > > nowTime.setMinutes(nowTime.getMinutes() +
    > >nowTime.getTimezoneOffset() +
    > > parseInt(timeDiff));

    >
    > There should be no need to use parseInt; and used thus it will probably
    > give incorrect results for differences of 08 & 09. Use unary +.
    >
    > alert(timeDiff) shows me an empty string.
    >
    > > resultsFrame.write(selectedCity + " time is " +
    > >getTimeString(nowTime));
    > > resultsFrame.close();
    > >}
    > >
    > ></SCRIPT>
    > ></HEAD>
    > ><BODY LANGUAGE=JavaScript onload="window_onload()">
    > ><FORM NAME=form1>
    > ><SELECT SIZE=5 NAME=lstCity LANGUAGE=JavaScript
    > >onchange="updateTimeZone(this);">
    > >
    > > <option>Paris</option>
    > >
    > ><option>London</option>
    > > <option>Rome</option>
    > > <option>New
    > >York</option>
    > >
    > ><option>Toronto</option>
    > >
    > ><option>Sydney</option>
    > >
    > ><option>Moscow</option>
    > > <option>Tokyo</option>
    > >
    > ><option>Beijing</option>
    > > <option>San
    > >Francisco</option>
    > > <option>Cairo</option>
    > >
    > ><option>Bangkok</option>
    > > <option>Lima</option>
    > >
    > > </select>
    > > </td>
    > > </tr>
    > > </table>
    > > </form>
    > > </td>
    > > </tr>
    > ></table>
    > ></body>
    > ></html>
    > >
    > >But I am having trouble trying to get it to work. Would anyone have an
    > >idea?

    >
    > Explain what trouble. For me, it fails since window.top.resultsFrame.
    > document is not an Object; don't presume that everyone sees the same.
    > Maybe you need to understand the use of "open". You could instead write
    > to a TextArea, for simplicity.
    >
    > ISTM that timeDiff is an empty string when in updateTime.
    >
    > You need to learn how to debug code. Write in smaller pieces, testing
    > as you go. Function alert() will show the value of a variable.
    >
    > I see no allowance for the Summer Time rules of each location.
    >
    > If this is coursework, consider a different career.
    >
    > If it represents a practical need, then js-date5.htm#Demo serves for any
    > location (even LHI <g>) and js-date5.htm#SLGD (was SLHD) serves for a
    > list of locations. While the latter input is a TextArea, the value is
    > immediately converted to an Array.
    >
    > It's a good idea to read the newsgroup and its FAQ.
    > --

    Thanks for your advice. Personally, I'm not fond of JavaScript. Don't
    really appreciate the following either "If this is coursework, consider
    a different career."
    Gregc., Sep 26, 2006
    #8
  9. JRS: In article <>,
    dated Mon, 25 Sep 2006 17:38:03 remote, seen in
    news:comp.lang.javascript, Gregc. <> posted :

    >Lines: 161


    >Dr John Stockton wrote:


    >> It's a good idea to read the newsgroup and its FAQ.
    >> --

    >Thanks for your advice. Personally, I'm not fond of JavaScript. Don't
    >really appreciate the following either "If this is coursework, consider
    >a different career."


    You have repeatedly been advised to read the FAQ; if you had done so,
    you would have known not to over-quote.

    You'll be better off in a career matching your intellectual capability.

    --
    © John Stockton, Surrey, UK. REPLYyyww merlyn demon co uk Turnpike 4 ©
    Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
    Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
    No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
    Dr John Stockton, Sep 26, 2006
    #9
  10. Gregc.

    Evertjan. Guest

    Dr John Stockton wrote on 26 Sep 2006 in comp.lang.javascript:

    > You'll be better off in a career matching your intellectual capability.


    Wow, John, that is just an assumption.

    I could put to you some incompatible assumptions,
    applicable to different individuals:

    A career below that capability could fuel and make time for intellectual
    hobbyism, that could enrich life and be a joy when your working days are
    over. [This could possibly apply to the majority on this NG?]

    A career over that capability could enlarge that capability,
    improving one's self esteem.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Sep 27, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CJ
    Replies:
    2
    Views:
    565
  2. Eric Wertman

    time module question - time zones

    Eric Wertman, May 21, 2008, in forum: Python
    Replies:
    0
    Views:
    486
    Eric Wertman
    May 21, 2008
  3. Eric Wertman

    Re: time module question - time zones

    Eric Wertman, May 21, 2008, in forum: Python
    Replies:
    0
    Views:
    484
    Eric Wertman
    May 21, 2008
  4. Harlan Messinger

    Dates, time zones,daylight saving time

    Harlan Messinger, Apr 15, 2010, in forum: ASP .Net
    Replies:
    1
    Views:
    989
    Eric Isaacs
    Apr 16, 2010
  5. David Graham

    cookie expire time and time zones

    David Graham, Nov 20, 2003, in forum: Javascript
    Replies:
    6
    Views:
    252
    Dr John Stockton
    Nov 22, 2003
Loading...

Share This Page