problem display date in firefox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franz

    #1

    problem display date in firefox

    Hy all,

    I have a problem with a date in javascript on firefox Browser.
    I use this javascript method:


    var dataNow=new Date();
    var dd=dataNow.getD ate();
    var mm=dataNow.getM onth()+1;
    var yy=dataNow.getY ear();


    Firefox does not display the date correctly.
    Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
    fine.


    How can i solve that??

    Thanks in advance.

    Franz.


  • Daniel Kirsch

    #2
    Re: problem display date in firefox

    Franz wrote:[color=blue]
    > var yy=dataNow.getY ear();
    >
    >
    > Firefox does not display the date correctly.
    > Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
    > fine.[/color]

    use
    getFullYear()

    Daniel

    Comment

    • Michael Winter

      #3
      Re: problem display date in firefox

      On 08/06/2005 09:50, Franz wrote:

      [snip]
      [color=blue]
      > var yy=dataNow.getY ear();
      >
      > Firefox does not display the date correctly.
      > Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
      > fine.[/color]

      Officially, there is no Date.prototype. getYear method, so an
      implementation can do what it likes. However, the recommended behaviour
      is the one displayed by Firefox: return the current year minus 1900.

      The Date.prototype. getFullYear method is preferred as it has consistent
      behaviour.

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Lee

        #4
        Re: problem display date in firefox

        Michael Winter said:[color=blue]
        >
        >On 08/06/2005 09:50, Franz wrote:
        >
        >[snip]
        >[color=green]
        >> var yy=dataNow.getY ear();
        >>
        >> Firefox does not display the date correctly.
        >> Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
        >> fine.[/color]
        >
        >Officially, there is no Date.prototype. getYear method, so an
        >implementati on can do what it likes. However, the recommended behaviour
        >is the one displayed by Firefox: return the current year minus 1900.[/color]

        Yesterday I saw an internal report that was timestamped "1050607".

        Comment

        • Dr John Stockton

          #5
          Re: problem display date in firefox

          JRS: In article <42a6b1a4_3@x-privat.org>, dated Wed, 8 Jun 2005
          10:50:57, seen in news:comp.lang. javascript, Franz
          <anonymous@anon ymous.com> posted :[color=blue]
          >I have a problem with a date in javascript on firefox Browser.
          >var yy=dataNow.getY ear();
          >
          >Firefox does not display the date correctly.
          >Instead of "2005" for the year, it displays "105", in IE Explorer, it looks
          >fine.[/color]
          [color=blue]
          >How can i solve that??[/color]

          By reading the newsgroup FAQ; see below.

          If you should need to support very very old browsers, you can use
          instead of getFullYear

          function getFY(D) { var YE
          YE = Math.round(D.ge tTime() / 31556952000) + 1970
          return YE + (D.getYear()-YE)%100 }

          from my page js-date0.htm. The estimate YE is adjusted so that its last
          two digits agree with getYear(). Of the numbers, only 100 needs to be
          exact.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          • Grant Wagner

            #6
            Re: problem display date in firefox

            "Michael Winter" <m.winter@bluey onder.co.invali d> wrote in message
            news:F3Ape.4717 5$G8.18665@text .news.blueyonde r.co.uk...[color=blue]
            > On 08/06/2005 09:50, Franz wrote:
            >
            > [snip]
            >[color=green]
            >> var yy=dataNow.getY ear();
            >>
            >> Firefox does not display the date correctly.
            >> Instead of "2005" for the year, it displays "105", in IE Explorer, it
            >> looks
            >> fine.[/color]
            >
            > Officially, there is no Date.prototype. getYear method, so an
            > implementation can do what it likes. However, the recommended
            > behaviour is the one displayed by Firefox: return the current year
            > minus 1900.
            >
            > The Date.prototype. getFullYear method is preferred as it has
            > consistent behaviour.[/color]

            If your script might run in an environment where
            Date.prototype. getFullYear is not available (since it was not introduced
            until JavaScript 1.3 and JScript 3), you might be better off making sure
            you a Date.prototype. getFullYear available:

            if ('function' != typeof Date.prototype. getFullYear)
            {
            Date.prototype. getFullYear = function()
            {
            return (this.getYear() % 1900) + 1900;
            }
            }

            --
            Grant Wagner <gwagner@agrico reunited.com>
            comp.lang.javas cript FAQ - http://jibbering.com/faq


            Comment

            • Dr John Stockton

              #7
              Re: problem display date in firefox

              JRS: In article <%Yjqe.2$va3.46 9@news2.mts.net >, dated Fri, 10 Jun 2005
              17:19:55, seen in news:comp.lang. javascript, Grant Wagner
              <gwagner@agrico reunited.com> posted :
              [color=blue]
              >If your script might run in an environment where
              >Date.prototype .getFullYear is not available (since it was not introduced
              >until JavaScript 1.3 and JScript 3), you might be better off making sure
              >you a Date.prototype. getFullYear available:[/color]

              Agreed so far.
              [color=blue]
              >if ('function' != typeof Date.prototype. getFullYear)
              >{
              > Date.prototype. getFullYear = function()
              > {
              > return (this.getYear() % 1900) + 1900;
              > }
              >}[/color]

              But only if the function always gives the correct result.

              I have read, possibly here, that :-
              "Method getYear can return any one of these three sequences for years :
              97,98,99,00,01 or 97,98,99,2000,2 001 or 97,98,99,100,10 1".

              For 2001, those are not all equal modulo 1900; hence, that method cannot
              always be right. I don't know which browser(s) give/gave 00,01.

              That's why, after some thought, I produced function getFY() as
              previously given in this thread and in my page js-date0.htm.



              However, if the date is known to be current,
              return 2000 + this.getYear()% 100
              will do for a while, and later on
              return 2050 + (this.getYear() +50)%100
              etc.

              --
              © 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...