dojo/date (version 1.10)

Summary

Date manipulation utilities

See the dojo/date reference documentation for more information.

Method Summary

  • add(date,interval,amount) Add to a Date in intervals of different size, from milliseconds to years
  • compare(date1,date2,portion) Compare two date objects by date, time, or both.
  • difference(date1,date2,interval) Get the difference in a specific unit of time (e.g., number of months, weeks, days, etc.) between two dates, rounded to the nearest integer.
  • getDaysInMonth(dateObject) Returns the number of days in the month used by dateObject
  • getTimezoneName(dateObject) Get the user's time zone as provided by the browser
  • isLeapYear(dateObject) Determines if the year of the dateObject is a leap year

Methods

add(date,interval,amount)
Defined by dojo/date

Add to a Date in intervals of different size, from milliseconds to years

Parameter Type Description
date Date

Date object to start with

interval String

A string representing the interval. One of the following: "year", "month", "day", "hour", "minute", "second", "millisecond", "quarter", "week", "weekday"

amount int

How much to add to the date.

Returns:instance
compare(date1,date2,portion)
Defined by dojo/date

Compare two date objects by date, time, or both.

Returns 0 if equal, positive if a > b, else negative.

Parameter Type Description
date1 Date

Date object

date2 Date
Optional

Date object. If not specified, the current Date is used.

portion String
Optional

A string indicating the "date" or "time" portion of a Date object. Compares both "date" and "time" by default. One of the following: "date", "time", "datetime"

Returns:number
difference(date1,date2,interval)
Defined by dojo/date

Get the difference in a specific unit of time (e.g., number of months, weeks, days, etc.) between two dates, rounded to the nearest integer.

Parameter Type Description
date1 Date

Date object

date2 Date
Optional

Date object. If not specified, the current Date is used.

interval String
Optional

A string representing the interval. One of the following: "year", "month", "day", "hour", "minute", "second", "millisecond", "quarter", "week", "weekday"

Defaults to "day".

Returns:undefined
getDaysInMonth(dateObject)
Defined by dojo/date

Returns the number of days in the month used by dateObject

Parameter Type Description
dateObject Date
Returns:number | undefined
getTimezoneName(dateObject)
Defined by dojo/date

Get the user's time zone as provided by the browser

Try to get time zone info from toString or toLocaleString method of the Date object -- UTC offset is not a time zone. See http://www.twinsun.com/tz/tz-link.htm Note: results may be inconsistent across browsers.

Parameter Type Description
dateObject Date

Needed because the timezone may vary with time (daylight savings)

Returns:undefined
isLeapYear(dateObject)
Defined by dojo/date

Determines if the year of the dateObject is a leap year

Leap years are years with an additional day YYYY-02-29, where the year number is a multiple of four with the following exception: If a year is a multiple of 100, then it is only a leap year if it is also a multiple of 400. For example, 1900 was not a leap year, but 2000 is one.

Parameter Type Description
dateObject Date
Returns:boolean
Error in the documentation? Can’t find what you are looking for? Let us know!