Daylight savings time etc...

Discussion in 'Javascript' started by jodleren, Jun 5, 2009.

  1. jodleren

    jodleren Guest

    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

    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!

    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

    WBR
    Sonnich
     
    jodleren, Jun 5, 2009
    #1
    1. Advertising

  2. jodleren

    GArlington Guest

    On Jun 5, 2:05 pm, jodleren <> wrote:
    > 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
    >
    > 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!

    I suspect that offset == 0 here...
    >
    > 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

    It is NOT Java, it is JavaScript
    >
    > WBR
    > Sonnich


    I can not understand what you were trying to do...
    Get server time (???) and display it in browser timezone?
    Something else?
     
    GArlington, Jun 5, 2009
    #2
    1. Advertising

  3. 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.
     
    Dr J R Stockton, Jun 5, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    1
    Views:
    1,483
    Ryan Ternier
    Oct 14, 2005
  2. lordy
    Replies:
    3
    Views:
    2,026
    lordy
    Jul 14, 2006
  3. js
    Replies:
    1
    Views:
    803
  4. dhanya
    Replies:
    2
    Views:
    316
    Noble
    Dec 1, 2006
  5. Washington Ratso
    Replies:
    1
    Views:
    83
    Chris “Kwpolska†Warrick
    Apr 3, 2014
Loading...

Share This Page