Month Date problem

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

    Month Date problem

    I have been using the javascript below on a web page since last August to
    show the "Site updated" month
    minus a month, which has been very successful, but January is showing a
    "undefined 2004" message.
    Help much appreciated
    Jim


    var m=new Array(13);var n=new Date()

    m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated
    March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated
    June";
    m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
    September";m[10]="Site updated October";m[11]="Site updated
    November";m[12]="Site updated December"
    document.write( m[n.getMonth()+0]+" "+n.getFullYear ())


  • Thomas A. Li

    #2
    Re: Month Date problem

    As of JDK version 1.1, replaced by Calendar.get(Ca lendar.MONTH).

    "Jim" <[email protected] om> wrote in message
    news:3ff86a2f$0 $11176$cc9e4d1f @news.dial.pipe x.com...[color=blue]
    > I have been using the javascript below on a web page since last August to
    > show the "Site updated" month
    > minus a month, which has been very successful, but January is showing a
    > "undefined 2004" message.
    > Help much appreciated
    > Jim
    >
    >
    > var m=new Array(13);var n=new Date()
    >
    > m[1]="Site updated January";m[2]="Site updated February";m[3]="Site[/color]
    updated[color=blue]
    > March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site[/color]
    updated[color=blue]
    > June";
    > m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
    > September";m[10]="Site updated October";m[11]="Site updated
    > November";m[12]="Site updated December"
    > document.write( m[n.getMonth()+0]+" "+n.getFullYear ())
    >
    >[/color]


    Comment

    • Edward Huang

      #3
      Re: Month Date problem

      It was caused when you invoked n.getMonth for January and got a
      returned number 0, which means January. Then you saw a word
      'undefined' extracted from an unassociated element m[0].

      To solve the problem, just write as follow,

      m[n.getMonth() - 1]

      "Jim" <[email protected] om> wrote in message news:<3ff86a2f$ 0$11176$cc9e4d1 [email protected] ex.com>...[color=blue]
      > I have been using the javascript below on a web page since last August to
      > show the "Site updated" month
      > minus a month, which has been very successful, but January is showing a
      > "undefined 2004" message.
      > Help much appreciated
      > Jim
      >
      >
      > var m=new Array(13);var n=new Date()
      >
      > m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated
      > March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated
      > June";
      > m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
      > September";m[10]="Site updated October";m[11]="Site updated
      > November";m[12]="Site updated December"
      > document.write( m[n.getMonth()+0]+" "+n.getFullYear ())[/color]

      Comment

      Working...