Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Time Zones

Reply
Thread Tools

Time Zones

 
 
Gregc.
Guest
Posts: n/a
 
      09-23-2006
Hi

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

Greg

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      09-23-2006
JRS: In article <(E-Mail Removed) .com>,
dated Sat, 23 Sep 2006 01:55:47 remote, seen in
news:comp.lang.javascript, Gregc. <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Gregc.
Guest
Posts: n/a
 
      09-24-2006

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

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-24-2006
JRS: In article <(E-Mail Removed). com>,
dated Sat, 23 Sep 2006 20:25:12 remote, seen in
news:comp.lang.javascript, Gregc. <(E-Mail Removed)> 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.
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      09-24-2006
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

 
Reply With Quote
 
Gregc.
Guest
Posts: n/a
 
      09-25-2006

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

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-25-2006
JRS: In article <(E-Mail Removed) .com>,
dated Mon, 25 Sep 2006 00:30:53 remote, seen in
news:comp.lang.javascript, Gregc. <(E-Mail Removed)> 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.
 
Reply With Quote
 
Gregc.
Guest
Posts: n/a
 
      09-26-2006

Dr John Stockton wrote:
> JRS: In article <(E-Mail Removed) .com>,
> dated Mon, 25 Sep 2006 00:30:53 remote, seen in
> news:comp.lang.javascript, Gregc. <(E-Mail Removed)> 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."

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-26-2006
JRS: In article <(E-Mail Removed). com>,
dated Mon, 25 Sep 2006 17:38:03 remote, seen in
news:comp.lang.javascript, Gregc. <(E-Mail Removed)> 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.
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-27-2006
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dates, time zones,daylight saving time Harlan Messinger ASP .Net 1 04-15-2010 11:27 PM
Re: time module question - time zones Eric Wertman Python 0 05-21-2008 04:40 PM
time module question - time zones Eric Wertman Python 0 05-21-2008 04:23 PM
OutputCache Duration across time zones? CJ ASP .Net 2 01-06-2006 04:59 PM
cookie expire time and time zones David Graham Javascript 6 11-22-2003 03:12 PM



Advertisments