By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,221 Members | 1,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,221 IT Pros & Developers. It's quick & easy.

system timzone offset on predetermined time

P: n/a
hi, can anyone help me out with this.

the requirement is to display a time (any time) from a distinct timezone
(lets say EST) on a webpage but to make available the conversion to the
user local timezone based on the users system time (presume the browser
headers contain this)

Guess im after a small function that takes a time and converts it to
another time based on the users browser system time

For example: the schedule of the Olympic Games may be displayed as this in
the USA (EST)

22 jan 10pm ET Javelin
22 jan 11pm ET Long Jump
23 jan 3am ET Shooting

but in the UK (GMT) would have to be (note date also changes):

23 jan 2am GMT Javelin
23 jan 3am GMT Long Jump
23 jan 7am GMT Shooting

Does anyone have any starting points for some code like this?
Mar 24 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Mar 24, 7:38 pm, adie <a...@oh-shit.comwrote:
hi, can anyone help me out with this.

the requirement is to display a time (any time) from a distinct timezone
(lets say EST) on a webpage but to make available the conversion to the
user local timezone based on the users system time (presume the browser
headers contain this)

Guess im after a small function that takes a time and converts it to
another time based on the users browser system time

For example: the schedule of the Olympic Games may be displayed as this in
the USA (EST)

22 jan 10pm ET Javelin
22 jan 11pm ET Long Jump
23 jan 3am ET Shooting

but in the UK (GMT) would have to be (note date also changes):

23 jan 2am GMT Javelin
23 jan 3am GMT Long Jump
23 jan 7am GMT Shooting

Does anyone have any starting points for some code like this?
>From the FAQ:
<URL: http://www.merlyn.demon.co.uk/js-dates.htm#UGU >

The big caveat with all the following is that it is dependent on the
local system being set correctly, and accurately. You have a copule
of strategies - you can publish all your events in UTC then subtract
the local timezone offset that is found (in minutes) by:

var d = new Date();
var timezoneOffset = d.getTimezoneOffset();

You can also use the Date object's UTC method with UTC date and time
data to construct a date object in local time, e.g. if an event is to
occur on 25 March 2007 at 06:30 am GMT (noting that months are zero
indexed: January is 0, February is 1, etc.):

var x = new Date(Date.UTC( 2007, 2, 25, 6, 30));
alert(x.toLocaleDateString()
+ ' ' + x.toLocaleTimeString() );
Wrapped in a function:

function utcToLocal(y, mo, d, h, mi, s) {
return new Date(Date.UTC( y, mo, d, h, mi, s));
}

// Events on 25 March, 2007 at 06:30 am and 10:15 pm UTC
alert(
utcToLocal(2007, 2, 25, 6, 30, 0).toLocaleString() + '\n' +
utcToLocal(2007, 2, 25, 22, 15, 0).toLocaleString()
);

toLocaleString is supposed to present the date and time based on
system settings, it's somewhat unreliable - despite being set for en-
au, Firefox and Opera show the much disliked month/day/year format.
Safari and IE get it right.
--
Rob

Mar 24 '07 #2

P: n/a
On 24 Mar 2007 05:23:13 -0700, RobG wrote:
On Mar 24, 7:38 pm, adie <a...@oh-shit.comwrote:
>hi, can anyone help me out with this.

the requirement is to display a time (any time) from a distinct timezone
(lets say EST) on a webpage but to make available the conversion to the
user local timezone based on the users system time (presume the browser
headers contain this)

Guess im after a small function that takes a time and converts it to
another time based on the users browser system time

For example: the schedule of the Olympic Games may be displayed as this in
the USA (EST)

22 jan 10pm ET Javelin
22 jan 11pm ET Long Jump
23 jan 3am ET Shooting

but in the UK (GMT) would have to be (note date also changes):

23 jan 2am GMT Javelin
23 jan 3am GMT Long Jump
23 jan 7am GMT Shooting

Does anyone have any starting points for some code like this?
>>From the FAQ:

<URL: http://www.merlyn.demon.co.uk/js-dates.htm#UGU >

The big caveat with all the following is that it is dependent on the
local system being set correctly, and accurately. You have a copule
of strategies - you can publish all your events in UTC then subtract
the local timezone offset that is found (in minutes) by:

var d = new Date();
var timezoneOffset = d.getTimezoneOffset();

You can also use the Date object's UTC method with UTC date and time
data to construct a date object in local time, e.g. if an event is to
occur on 25 March 2007 at 06:30 am GMT (noting that months are zero
indexed: January is 0, February is 1, etc.):

var x = new Date(Date.UTC( 2007, 2, 25, 6, 30));
alert(x.toLocaleDateString()
+ ' ' + x.toLocaleTimeString() );
Wrapped in a function:

function utcToLocal(y, mo, d, h, mi, s) {
return new Date(Date.UTC( y, mo, d, h, mi, s));
}

// Events on 25 March, 2007 at 06:30 am and 10:15 pm UTC
alert(
utcToLocal(2007, 2, 25, 6, 30, 0).toLocaleString() + '\n' +
utcToLocal(2007, 2, 25, 22, 15, 0).toLocaleString()
);

toLocaleString is supposed to present the date and time based on
system settings, it's somewhat unreliable - despite being set for en-
au, Firefox and Opera show the much disliked month/day/year format.
Safari and IE get it right.
Looks good, but all our dates are EST, will it still work? :-) Sorry to be
complicated...
Mar 24 '07 #3

P: n/a
adie wrote on 24 mrt 2007 in comp.lang.javascript:
Looks good, but all our dates are EST, will it still work? :-) Sorry
to be complicated...
You can easily test it yourself, even to the point that you temporarily set
up a client virtually based in Hong Kong, Amsterdam or Honolulu.

Serverside ASP jscript holds the right UTC and the right server local time,
if the server regional settings are set up correctly.

Those settings are your responsability.
Clientside j[ava]script shows the right UTC and the right cleantlocal time,
if the client regional settings are set up correctly.

Those settings are the user's responsability.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 24 '07 #4

P: n/a
In comp.lang.javascript message <14qapjqmye78s$.xh73nkck7lmw.dlg@40tude.
net>, Sat, 24 Mar 2007 09:38:53, adie <ad**@oh-shit.composted:
>the requirement is to display a time (any time) from a distinct timezone
(lets say EST) on a webpage but to make available the conversion to the
user local timezone based on the users system time (presume the browser
headers contain this)
An EST date/time can be converted to UTC by a browser anywhere, provided
that the browser is also supplied with the time zone and summer time
rules for the relevant EST (Hint :- EVERY country has an Easternmost
part, and some of them have a Time Zone covering only that part of their
country), and that the rules are up-to-date (well, actually they must be
correct for the date in question), and that the time exists and is not
in the Ambiguous Autumnal Hour.

In order not to be pig-headed, you need to convert your local times to
Universal times (UTC/GMT), and to do so locally, for distribution. You
should know how your EST relates to GMT, if you live in the local EST
area. And if you do not, javascript can do it easily, on a browser
configured for your locality.

Or, better, just ignore your local time and start with UTC.

Then your transmitted data contains the UTC - since no-one really needs
to see this, send it as what +new Date() would give if run
(anywhere) on a correctly-set system at the actual time of the event.
That recently was 1174843625425 (it's milliseconds from 1970-01-01
00:00:00 Z, of course).

Then in the Web page, use new Date(ThatNumber) and output it; either
naively, to get an uncertain but locally-acceptable format for
correctly-localised browsers, or by specific code to get local time in a
globally-unambiguous format.

That means in ISO 8601, of course. Mark it as LCT, since you do not
know, and cannot determine, any other abbreviation.
>Guess im after a small function that takes a time and converts it to
another time based on the users browser system time

For example: the schedule of the Olympic Games may be displayed as this in
the USA (EST)

22 jan 10pm ET Javelin
22 jan 11pm ET Long Jump
23 jan 3am ET Shooting
ET is Ephemeris Time - only astronomers will want that.
>but in the UK (GMT) would have to be (note date also changes):

23 jan 2am GMT Javelin
23 jan 3am GMT Long Jump
23 jan 7am GMT Shooting
Many in the UK will not like that format - many round here would like
month names in Hangul, for example. Use ISO 8601.

For the 2008 Games, the times will be originated in China Time, GMT+8,
but may be delivered in UTC.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 25 '07 #5

P: n/a
On Sun, 25 Mar 2007 18:34:07 +0100, Dr J R Stockton wrote:
In comp.lang.javascript message <14qapjqmye78s$.xh73nkck7lmw.dlg@40tude.
net>, Sat, 24 Mar 2007 09:38:53, adie <ad**@oh-shit.composted:
>>the requirement is to display a time (any time) from a distinct timezone
(lets say EST) on a webpage but to make available the conversion to the
user local timezone based on the users system time (presume the browser
headers contain this)

An EST date/time can be converted to UTC by a browser anywhere, provided
that the browser is also supplied with the time zone and summer time
rules for the relevant EST (Hint :- EVERY country has an Easternmost
part, and some of them have a Time Zone covering only that part of their
country), and that the rules are up-to-date (well, actually they must be
correct for the date in question), and that the time exists and is not
in the Ambiguous Autumnal Hour.

In order not to be pig-headed, you need to convert your local times to
Universal times (UTC/GMT), and to do so locally, for distribution. You
should know how your EST relates to GMT, if you live in the local EST
area. And if you do not, javascript can do it easily, on a browser
configured for your locality.

Or, better, just ignore your local time and start with UTC.

Then your transmitted data contains the UTC - since no-one really needs
to see this, send it as what +new Date() would give if run
(anywhere) on a correctly-set system at the actual time of the event.
That recently was 1174843625425 (it's milliseconds from 1970-01-01
00:00:00 Z, of course).

Then in the Web page, use new Date(ThatNumber) and output it; either
naively, to get an uncertain but locally-acceptable format for
correctly-localised browsers, or by specific code to get local time in a
globally-unambiguous format.

That means in ISO 8601, of course. Mark it as LCT, since you do not
know, and cannot determine, any other abbreviation.
>>Guess im after a small function that takes a time and converts it to
another time based on the users browser system time

For example: the schedule of the Olympic Games may be displayed as this in
the USA (EST)

22 jan 10pm ET Javelin
22 jan 11pm ET Long Jump
23 jan 3am ET Shooting

ET is Ephemeris Time - only astronomers will want that.
>>but in the UK (GMT) would have to be (note date also changes):

23 jan 2am GMT Javelin
23 jan 3am GMT Long Jump
23 jan 7am GMT Shooting

Many in the UK will not like that format - many round here would like
month names in Hangul, for example. Use ISO 8601.

For the 2008 Games, the times will be originated in China Time, GMT+8,
but may be delivered in UTC.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
Thanks doc, will follow up on that. Mind if i mail your smart ass if
needed?
Mar 28 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.