.getYear function work in IE only?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • What-a-Tool

    #1

    .getYear function work in IE only?

    Why is it that the following code displays "2005" in IE, but "105" in every
    other browser I've tried?

    var mydt = new Date();
    var myyr = mydt.getYear();
    document.write( "<p>Year Test : "+myyr+"</p>");

    Thanks in advance

    --

    / Sean the Mc /

    "Opinions are like flatulence - everyone loves the sound of their own, but
    anyone else's usually just stinks !"
    -anonymous



  • Lasse Reichstein Nielsen

    #2
    Re: .getYear function work in IE only?

    "What-a-Tool" <Die!FrigginSpa mmers!DieDie!@I HateSpam.Com> writes:
    [color=blue]
    > Why is it that the following code displays "2005" in IE, but "105" in every
    > other browser I've tried?[/color]

    When IE does one thing and every other browser does something else, I'd put
    money on IE not following the standard.

    In this case, there actually is no standard. ECMA 262 only suggests a behavior
    for getYear, and Microsoft has chosen not to follow it.
    ---
    B.2.4 Date.prototype. getYear ( )
    NOTE
    The getFullYear method is preferred for nearly all purposes, because it avoids the "year 2000 problem."
    When the getYear method is called with no arguments the following steps are taken:
    1. Let t be this time value.
    2. If t is NaN, return NaN.
    3. Return YearFromTime(Lo calTime(t)) - 1900.
    ---

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • McKirahan

      #3
      Re: .getYear function work in IE only?

      "What-a-Tool" <Die!FrigginSpa mmers!DieDie!@I HateSpam.Com> wrote in message
      news:VJmZd.6402 6$SF.11918@lake read08...[color=blue]
      > Why is it that the following code displays "2005" in IE, but "105" in[/color]
      every[color=blue]
      > other browser I've tried?
      >
      > var mydt = new Date();
      > var myyr = mydt.getYear();
      > document.write( "<p>Year Test : "+myyr+"</p>");
      >
      > Thanks in advance
      >
      > --
      >
      > / Sean the Mc /
      >
      > "Opinions are like flatulence - everyone loves the sound of their own, but
      > anyone else's usually just stinks !"
      > -anonymous
      >[/color]

      try .getFullYear()


      Comment

      • What-a-Tool

        #4
        Re: .getYear function work in IE only?


        "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
        news:ll8qvt12.f sf@hotpop.com.. .[color=blue]
        > "What-a-Tool" <Die!FrigginSpa mmers!DieDie!@I HateSpam.Com> writes:
        >[color=green]
        >> Why is it that the following code displays "2005" in IE, but "105" in
        >> every
        >> other browser I've tried?[/color]
        >
        > When IE does one thing and every other browser does something else, I'd
        > put
        > money on IE not following the standard.
        >
        > In this case, there actually is no standard. ECMA 262 only suggests a
        > behavior
        > for getYear, and Microsoft has chosen not to follow it.
        > ---
        > B.2.4 Date.prototype. getYear ( )
        > NOTE
        > The getFullYear method is preferred for nearly all purposes, because it
        > avoids the "year 2000 problem."
        > When the getYear method is called with no arguments the following steps
        > are taken:
        > 1. Let t be this time value.
        > 2. If t is NaN, return NaN.
        > 3. Return YearFromTime(Lo calTime(t)) - 1900.
        > ---
        >
        > /L
        > --
        > Lasse Reichstein Nielsen - lrn@hotpop.com
        > DHTML Death Colors:
        > <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        > 'Faith without judgement merely degrades the spirit divine.'[/color]


        ------------------------------------------------------------------

        AhHah! Thanks for the help

        --

        / Sean the Mc /

        "Opinions are like flatulence - everyone loves the sound of their own, but
        anyone else's usually just stinks !"
        -anonymous



        Comment

        • Douglas Crockford

          #5
          Re: .getYear function work in IE only?

          >>Why is it that the following code displays "2005" in IE, but "105" in every[color=blue][color=green]
          >>other browser I've tried?[/color][/color]
          [color=blue]
          > When IE does one thing and every other browser does something else, I'd put
          > money on IE not following the standard.
          >
          > In this case, there actually is no standard. ECMA 262 only suggests a behavior
          > for getYear, and Microsoft has chosen not to follow it.
          > ---
          > B.2.4 Date.prototype. getYear ( )
          > NOTE
          > The getFullYear method is preferred for nearly all purposes, because it avoids the "year 2000 problem."
          > When the getYear method is called with no arguments the following steps are taken:
          > 1. Let t be this time value.
          > 2. If t is NaN, return NaN.
          > 3. Return YearFromTime(Lo calTime(t)) - 1900.
          > ---[/color]

          JavaScript was released in 1995, and was not Y2K ready.
          In Microsoft's defense, the suggested behavior is stupid.

          Cosmetically, I think year % 100 would have been a better choice,
          but at least Microsoft's choice is defensible.


          Comment

          • Dr John Stockton

            #6
            Re: .getYear function work in IE only?

            JRS: In article <VJmZd.64026$SF .11918@lakeread 08>, dated Mon, 14 Mar
            2005 15:45:51, seen in news:comp.lang. javascript, What-a-Tool <Die!Frigg
            inSpammers!DieD ie!@IHateSpam.C om> posted :
            [color=blue]
            >Why is it that the following code displays "2005" in IE, but "105" in every
            >other browser I've tried?[/color]

            Because, AIUI, you have not yet tried enough browsers. I've heard that
            5 can be returned by getYear().

            Read the newsgroup FAQ; see below.

            Use instead getFullYear, unless you need to support very old systems; in
            that case, use a function getFY that calculates the proper year number
            from getYear and getTime .

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
            Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
            PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
            Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

            Comment

            Working...