The goog.date.DateTime Class

goog.date.DateTime
> goog.date.Date

goog.date.DateTime(opt_year, opt_month, opt_date, opt_hours, opt_minutes, opt_seconds, opt_milliseconds)

Class representing a date and time. Defaults to current date and time if none is specified. Implements most methods of the native js Date object and can be used interchangeably with it just as if goog.date.DateTime was a subclass of Date.

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.
opt_hours {number=}
Hours, 0 - 24.
opt_minutes {number=}
Minutes, 0 - 59.
opt_seconds {number=}
Seconds, 0 - 61.
opt_milliseconds {number=}
Milliseconds, 0 - 999.

.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.DateTime}
A clone of the datetime object.

.equals(other)

Tests whether given datetime is exactly equal to this DateTime.

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

.fromRfc822String(formatted)

Creates a DateTime from a datetime string expressed in RFC 822 format.

formatted {string}
A date or datetime expressed in RFC 822 format.
returns {goog.date.DateTime}
Parsed date or null if parse fails.

.getDate()

Inherited from goog.date.Date .

returns {number}
The date of month.

.getDay()

Inherited from goog.date.Date .

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

.getDayOfYear()

Inherited from goog.date.Date .

returns {number}
The day of year.

.getFirstDayOfWeek()

Inherited from goog.date.Date .

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

.getFirstWeekCutOffDay()

Inherited from goog.date.Date .

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

.getFullYear()

Inherited from goog.date.Date .

returns {number}
The four digit year of date.

.getHours()

Returns the hours part of the datetime.

returns {number}
An integer between 0 and 23, representing the hour.

.getIsoWeekday()

Inherited from goog.date.Date .

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

.getMilliseconds()

Returns the milliseconds part of the datetime.

returns {number}
An integer between 0 and 999, representing the milliseconds.

.getMinutes()

Returns the minutes part of the datetime.

returns {number}
An integer between 0 and 59, representing the minutes.

.getMonth()

Inherited from goog.date.Date .

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

.getNumberOfDaysInMonth()

Inherited from goog.date.Date .

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

.getSeconds()

Returns the seconds part of the datetime.

returns {number}
An integer between 0 and 59, representing the seconds.

.getTime()

Inherited from goog.date.Date .

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()

Inherited from goog.date.Date .

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()

Inherited from goog.date.Date .

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()

Inherited from goog.date.Date .

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

.getUTCDay()

Returns the day of week according to universal time, US style.

returns {goog.date.weekDay}
Day of week, 0 = Sun, 1 = Mon, 6 = Sat.

.getUTCFullYear()

Inherited from goog.date.Date .

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

.getUTCHours()

Returns the hours part of the datetime according to universal time.

returns {number}
An integer between 0 and 23, representing the hour.

.getUTCIsoWeekday()

Inherited from goog.date.Date .

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

.getUTCMilliseconds()

Returns the milliseconds part of the datetime according to universal time.

returns {number}
An integer between 0 and 999, representing the milliseconds.

.getUTCMinutes()

Returns the minutes part of the datetime according to universal time.

returns {number}
An integer between 0 and 59, representing the minutes.

.getUTCMonth()

Inherited from goog.date.Date .

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

.getUTCSeconds()

Returns the seconds part of the datetime according to universal time.

returns {number}
An integer between 0 and 59, representing the seconds.

.getUTCWeekday()

Inherited from goog.date.Date .

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

.getWeekNumber()

Inherited from goog.date.Date .

returns {number}
The week number.

.getWeekday()

Inherited from goog.date.Date .

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

.getYear()

Inherited from goog.date.Date .

Alias for getFullYear.

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

.set(date)

Inherited from goog.date.Date .

Sets the date.

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

.setDate(date)

Inherited from goog.date.Date .

Sets the day part of the date.

date {number}
The day part.

.setFirstDayOfWeek(day)

Inherited from goog.date.Date .

Sets the first day of week.

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

.setFirstWeekCutOffDay(day)

Inherited from goog.date.Date .

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

day {number}
The cut off weekday.

.setFullYear(year)

Inherited from goog.date.Date .

Sets the year part of the date.

year {number}
Four digit year.

.setHours(hours)

Sets the hours part of the datetime.

hours {number}
An integer between 0 and 23, representing the hour.

.setMilliseconds(ms)

Sets the seconds part of the datetime.

ms {number}
Integer between 0 and 999, representing the milliseconds.

.setMinutes(minutes)

Sets the minutes part of the datetime.

minutes {number}
Integer between 0 and 59, representing the minutes.

.setMonth(month)

Inherited from goog.date.Date .

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

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

.setSeconds(seconds)

Sets the seconds part of the datetime.

seconds {number}
Integer between 0 and 59, representing the seconds.

.setTime(ms)

Inherited from goog.date.Date .

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)

Inherited from goog.date.Date .

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

date {number}
The UTC date.

.setUTCFullYear(year)

Inherited from goog.date.Date .

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

year {number}
Four digit year.

.setUTCHours(hours)

Sets the hours part of the datetime according to universal time.

hours {number}
An integer between 0 and 23, representing the hour.

.setUTCMilliseconds(ms)

Sets the seconds part of the datetime according to universal time.

ms {number}
Integer between 0 and 999, representing the milliseconds.

.setUTCMinutes(minutes)

Sets the minutes part of the datetime according to universal time.

minutes {number}
Integer between 0 and 59, representing the minutes.

.setUTCMonth(month)

Inherited from goog.date.Date .

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

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

.setUTCSeconds(seconds)

Sets the seconds part of the datetime according to universal time.

seconds {number}
Integer between 0 and 59, representing the seconds.

.setYear(year)

Inherited from goog.date.Date .

Alias for setFullYear.

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

.toIsoString(opt_verbose, opt_tz)

Returns ISO 8601 string representation of date/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/time.

.toIsoTimeString(opt_showSeconds)

Generates time label for the datetime in standard ISO 24-hour time format. E.g., '06:00:00' or '23:30:15'.

opt_showSeconds {boolean=}
Whether to shows seconds. Defaults to TRUE.
returns {string}
The time label.

.toString()

Overloaded toString method for object.

returns {string}
ISO 8601 string representation of date/time.

.toUTCIsoString(opt_verbose, opt_tz)

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

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

.toUsTimeString(opt_padHours, opt_showAmPm, opt_omitZeroMinutes)

Generates time label for the datetime, e.g., '5:30am'. By default this does not pad hours (e.g., to '05:30') and it does add an am/pm suffix. TODO(user): i18n -- hardcoding time format like this is bad. E.g., in CJK locales, need Chinese characters for hour and minute units.

opt_padHours {boolean=}
Whether to pad hours, e.g., '05:30' vs '5:30'.
opt_showAmPm {boolean=}
Whether to show the 'am' and 'pm' suffix.
opt_omitZeroMinutes {boolean=}
E.g., '5:00pm' becomes '5pm', but '5:01pm' remains '5:01pm'.
returns {string}
The time label.

.toXmlDateTime(opt_timezone)

Returns XML Schema 2 string representation of date/time. The return value is also ISO 8601 compliant.

opt_timezone {boolean=}
Should the timezone offset be included in the string?.
returns {string}
XML Schema 2 string representation of date/time.

.valueOf()

Inherited from goog.date.Date .

returns {number}
Value of wrapped date.