473,545 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

system timzone offset on predetermined time

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
5 3203
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.getTimezoneOf fset();

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.toLocal eDateString()
+ ' ' + x.toLocaleTimeS tring() );
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).toLocaleStri ng() + '\n' +
utcToLocal(2007 , 2, 25, 22, 15, 0).toLocaleStri ng()
);

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
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.getTimezoneOf fset();

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.toLocal eDateString()
+ ' ' + x.toLocaleTimeS tring() );
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).toLocaleStri ng() + '\n' +
utcToLocal(2007 , 2, 25, 22, 15, 0).toLocaleStri ng()
);

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
adie wrote on 24 mrt 2007 in comp.lang.javas cript:
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
In comp.lang.javas cript message <14qapjqmye78s$ .xh73nkck7lmw.d lg@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.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 25 '07 #5
On Sun, 25 Mar 2007 18:34:07 +0100, Dr J R Stockton wrote:
In comp.lang.javas cript message <14qapjqmye78s$ .xh73nkck7lmw.d lg@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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5760
by: D. Dante Lorenso | last post by:
I need to know that original number of rows that WOULD have been returned by a SELECT statement if the LIMIT / OFFSET where not present in the statement. Is there a way to get this data from PG ? SELECT ... ; ----> returns 100,000 rows
2
11921
by: stephen fx | last post by:
Hello all! Using C/C++ I can do this: struct MyStruct { int a; char b; }; MyStruct test;
3
15272
by: MJB | last post by:
I'm getting an IStream back from function xmlHttp.responsestream. I would like to convert this to a System.IO.Stream in order to work with it in my application. Has anyone encountered this and written a conversion? TIA, Matt
0
339
by: Asaf | last post by:
Hi, When I am doing a POST to a SSL URL I am getting this error on first attempt "Cannot access a disposed object named "System.Net.TlsStream"." After the first attempt all works fine, here is the Stack Trace at System.Net.TlsStream.InnerWrite(Boolean async, Byte buffer, Int32 offset, Int32 size, AsyncCallback asyncCallback, Object...
14
3645
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style of date formatting (RFC 822). I have been using a variation of RFC 1123 (just change the time zone to an offset, i.e. "-0800"). It seems to be...
0
11220
by: Aryeh Holzer | last post by:
Hi, I've been trying to use the weather webservice available from the National Weather Service (NWS), at http://www.nws.noaa.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML. wsdl without success. Here's what I've found so far. When I use .NET 1.0/1.1, and try to call the primary webservice method NDFDgen, the call will succeed if the productType is...
11
2466
by: ulyses | last post by:
Let's assume I have following file: 2938929384902491233..... 923949919199191919112.... File contains INTs only. What is more they are huge. For example first row in file may contain integer which size is 50MB and the second 30MB. Now we come to my problem. Is there possibility to swap this rows without using system memory (preferably in...
2
6812
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how to fix this error. I am able to send messages sometimes both other times randomly following error appear EXCEPTION:
4
216
by: Gabriel Rossetti | last post by:
Hello everyone! I trying to work with time and I a bit confused... If I look at my clock, it's 16:59 (4:59pm), if I type "date" in a terminal, it says the same thing. I'm wanting to write a simple NTP-type server/client (it's not NTP at all actually, but does the same thing). The idea is that a client sends it it's UTC offset and it returns...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5341
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.