The goog.date.Date Class

goog.date.Date(opt_year, opt_month, opt_date)

Class representing a date. Defaults to current date if none is specified. Implements most methods of the native js Date object (except the time related ones, {@see goog.date.DateTime}) and can be used interchangeably with it just as if goog.date.Date was a synonym of Date. To make this more transparent, Closure APIs should accept goog.date.DateLike instead of the real Date object. To allow goog.date.Date objects to be passed as arguments to methods expecting Date objects this class is marked as extending the built in Date object even though that's not strictly true.

opt_year {number|Object=}
Four digit year or a date-like object. If not set, the created object will contain the date determined by goog.now().
opt_month {number=}
Month, 0 = Jan, 11 = Dec.
opt_date {number=}
Date of month, 1 - 31.
@see
goog.date.DateTime

.add(interval)

Performs date calculation by adding the supplied interval to the date.

interval {goog.date.Interval}
Date interval to add.

.clone()

returns {!goog.date.Date}
A clone of the date object.

.compare(date1, date2)

Compares two dates. May be used as a sorting function.

date1 {!goog.date.DateLike}
Date to compare.
date2 {!goog.date.DateLike}
Date to compare.
returns {number}
Comparison result. 0 if dates are the same, less than 0 if date1 is earlier than date2, greater than 0 if date1 is later than date2.
@see
goog.array.sort

.equals(other)

Tests whether given date is equal to this Date. Note: This ignores units more precise than days (hours and below) and also ignores timezone considerations.

other {goog.date.Date}
The date to compare.
returns {boolean}
Whether the given date is equal to this one.

.getDate()

returns {number}
The date of month.

.getDay()

returns {goog.date.weekDay}
The day of week, US style. 0 = Sun, 6 = Sat.

.getDayOfYear()

returns {number}
The day of year.

.getFirstDayOfWeek()

returns {number}
The first day of the week. 0 = Mon, 6 = Sun.

.getFirstWeekCutOffDay()

returns {number}
The cut off weekday used for week number calculations. 0 = Mon, 6 = Sun.

.getFullYear()

returns {number}
The four digit year of date.

.getIsoWeekday()

returns {number}
The day of week, ISO style. 0 = Mon, 6 = Sun.

.getMonth()

returns {goog.date.month}
The month of date, 0 = Jan, 11 = Dec.

.getNumberOfDaysInMonth()

returns {number}
The number of days for the selected month.

.getTime()

Returns the number of milliseconds since 1 January 1970 00:00:00.

returns {number}
The number of milliseconds since 1 January 1970 00:00:00.

.getTimezoneOffset()

Returns timezone offset. The timezone offset is the delta in minutes between UTC and your local time. E.g., UTC+10 returns -600. Daylight savings time prevents this value from being constant.

returns {number}
The timezone offset.

.getTimezoneOffsetString()

Returns timezone offset as a string. Returns offset in [+-]HH:mm format or Z for UTC.

returns {string}
The timezone offset as a string.

.getUTCDate()

returns {number}
The date of month according to universal time.

.getUTCDay()

returns {goog.date.weekDay}
The day of week according to universal time, US style. 0 = Sun, 1 = Mon, 6 = Sat.

.getUTCFullYear()

returns {number}
The four digit year of date according to universal time.

.getUTCHours()

returns {number}
The hours value according to universal time.

.getUTCIsoWeekday()

returns {number}
The day of week according to universal time, ISO style. 0 = Mon, 6 = Sun.

.getUTCMinutes()

returns {number}
The hours value according to universal time.

.getUTCMonth()

returns {goog.date.month}
The month of date according to universal time, 0 = Jan, 11 = Dec.

.getUTCWeekday()

returns {number}
The day of week according to universal time and firstDayOfWeek setting.

.getWeekNumber()

returns {number}
The week number.

.getWeekday()

returns {number}
The day of week according to firstDayOfWeek setting.

.getYear()

Alias for getFullYear.

returns {number}
The four digit year of date.
@see
#getFullyear

.set(date)

Sets the date.

date {goog.date.Date}
Date object to set date from.

.setDate(date)

Sets the day part of the date.

date {number}
The day part.

.setFirstDayOfWeek(day)

Sets the first day of week.

day {number}
0 = Mon, 6 = Sun.

.setFirstWeekCutOffDay(day)

Sets cut off weekday used for week number calculations. 0 = Mon, 6 = Sun.

day {number}
The cut off weekday.

.setFullYear(year)

Sets the year part of the date.

year {number}
Four digit year.

.setMonth(month)

Sets the month part of the date. TODO(nnaze): Update type to goog.date.month.

month {number}
The month, where 0 = Jan, 11 = Dec.

.setTime(ms)

Sets the value of the date object as expressed in the number of milliseconds since 1 January 1970 00:00:00.

ms {number}
Number of milliseconds since 1 Jan 1970.

.setUTCDate(date)

Sets the day part of the date according to universal time.

date {number}
The UTC date.

.setUTCFullYear(year)

Sets the year part of the date according to universal time.

year {number}
Four digit year.

.setUTCMonth(month)

Sets the month part of the date according to universal time.

month {number}
The month, where 0 = Jan, 11 = Dec.

.setYear(year)

Alias for setFullYear.

year {number}
Four digit year.
@see
#setFullYear

.toIsoString(opt_verbose, opt_tz)

Returns ISO 8601 string representation of date.

opt_verbose {boolean=}
Whether the verbose format should be used instead of the default compact one.
opt_tz {boolean=}
Whether the timezone offset should be included in the string.
returns {string}
ISO 8601 string representation of date.

.toString()

Overloaded toString method for object.

returns {string}
ISO 8601 string representation of date.

.toUTCIsoString(opt_verbose, opt_tz)

Returns ISO 8601 string representation of date according to universal time.

opt_verbose {boolean=}
Whether the verbose format should be used instead of the default compact one.
opt_tz {boolean=}
Whether the timezone offset should be included in the string.
returns {string}
ISO 8601 string representation of date according to universal time.

.valueOf()

returns {number}
Value of wrapped date.