473,657 Members | 2,409 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 3206
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
5775
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
11927
by: stephen fx | last post by:
Hello all! Using C/C++ I can do this: struct MyStruct { int a; char b; }; MyStruct test;
3
15296
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 asyncState) at System.Net.TlsStream.BeginWrite(Byte buffer, Int32 offset, Int32 size, AsyncCallback...
14
3665
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 writing okay, but it's failing to parse. I've tried changing the regional & language settings in my...
0
11242
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 set to "glance", but fail if set to "time- series".
11
2488
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 Unix/Linux)? Is there any function in C to do this?
2
6817
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 the current time, so the server side checks the time and adds the UTC offset given by the client....
0
8394
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4152
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
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.