In comp.lang.javascript message <b3d6b08c-51db-43b9-9ff9-d2cf3ba529ee@o1
4g2000vbo.googlegroups.com>, Fri, 5 Jun 2009 06:05:38, jodleren
<> posted:
>I just got an idea... as others working with time / ajax getting a
>correct timer is a problem.
>
>I looks at
>
> d = new Date();
> offset=Math.abs(d.getTimezoneOffset())/60
********
So you don't care whether you are in Estonia or half-way across the
Atlantic?
>but that returns 3, while I am at GMT+2. date.getHours adds tne 2 hrs
>causing my probvlem.
>Then I realised, that the answer is in front of me.
>
> var d = new Date();
> t=new Date(new Date() - d);
> offset=t.getHours(); // time offset!
The argument of t = new Date( ) will probably be zero, otherwise a
small positive integer. Therefore, T will represent 1970-01-01 00:00:00
and maybe a few milliseconds. You could more easily have used T = new
Date(0) .
For locations where News Year's Day uses Standard Time, that will give
the number of your Time Zone, with London being in Zone 0 and increasing
Eastwards to the Azores & Cape Verde.
For locations where New Year's Day uses Summer Time like Wagga Wagga and
Waitangi, it will be wrong by an hour. I'm not sure what LHI should
give.
To get the nominal central longitude, or number, of the local time zone,
correctly, go via <URL:http://www.merlyn.demon.co.uk/js-dates.htm>.
>This is what I am looking for at all times.
>Probably there is a better way of getting the time "0", but I am not
>that much a java freek
The first thing to learn about a language is its name. Java questions
go in groups like comp.lang.java.programmer.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<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.
|