• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Setting the Date

When you perform date arithmetic, you often have to change the value of an existing Date object. For example, an ecommerce script might have to calculate a date that is 90 days from the date that a sale occurs. To do this kind of thing, it's usually easiest to create a Date object and then use an expression or literal value to change the year, month, or some other component of the date. You do that by using the Date object methods listed in Table 13.3.

Table 13.3. Date Object Methods That Set Date Values
Method SyntaxJavaScript VersionWhat It Sets
Date_Object.setFullYear(yyyy)1.2The year as a four-digit number (1999, 2000, etc.)
Date_Object.setYear(yy)1.0The year as a two- or four-digit number (see Caution, below)
Date_Object.setMonth(mth)1.0The month of the year; from 0 (January) to 11 (December)
Date_Object.setDate(dd)1.0The date in the month; from 1 to 31
Date_Object.setHours(hh)1.0The hour of the day; from 0 (midnight) to 23 (11:00 PM)
Date_Object.setMinutes(mm)1.0The minute of the hour; from 0 to 59
Date_Object.setSeconds(ss)1.0The second of the minute; from 0 to 59
Date_Object.setMilliseconds(ms)1.2The milliseconds of the second; from 0 to 999
Date_Object.setTime(ms)1.0The milliseconds since January 1, 1970 GMT



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint