Date

Moduleejs
Definitionfinal class Date
InheritanceDate inherit Object
StabilityEvolving.

General purpose class for representing and working with dates, times, time spans and time zones.


Properties

QualifiersPropertyTypeDescription
get set dateNumberThe day of the month (1-31). If a value outside the range is given, the date is adjusted without error.
get set dayNumberThe day of the week (0 - 6, where 0 is Sunday) in local time. If a value outside the range is given, the date is adjusted without error.
get set dayOfYearNumberThe day of the year (0 - 365) in local time. If a value outside the range is given, the date is adjusted without error.
get elapsedNumberTime in milliseconds since the date object was constructed.
get set hoursNumberThe current hour (0 - 23) in local time. If a value outside the range is given, the date is adjusted without error.
get set millisecondsNumberThe current millisecond (0 - 999) in local time. If a value outside the range is given, the date is adjusted without error.
get set minutesNumberThe current minute (0 - 59) in local time. If a value outside the range is given, the date is adjusted without error.
get set monthNumberThe current month (0 - 11) in local time. If a value outside the range is given, the date is adjusted without error.
get set secondsNumberThe current second (0 - 59) in local time. If a value outside the range is given, the date is adjusted without error.
static get ticksNumberReturn a high resolution CPU tick counter. If the platform cannot provide such a counter, the call will return the now value in milliseconds.
get set timeNumberThe number of milliseconds since midnight, January 1st, 1970 UTC and the current date object. This is the same as Date.now().
get set yearNumberThe year in local time. This is the full year. E.g. A date of the year 2010 will return the number 2010.

Date Class Methods

QualifiersMethod
static UTC(year: Number, month: Number, day: Number, hours: Number = 0, minutes: Number = 0, seconds: Number = 0, milliseconds: Number = 0): Number
 Calculate the number of milliseconds since the epoch for a UTC time.
static now(): Number
 Return the current time as milliseconds since Jan 1 1970.
static parse(dateString: String): Number
 Parse a date string and return the number of milliseconds since midnight, January 1st, 1970 UTC.
static parseDate(dateString: String, defaultDate: Date = null): Date
 Parse a date string and Return a new Date object.
static parseUTCDate(dateString: String, defaultDate: Date = null): Date
 Parse a date string and Return a new Date object.

Date Instance Methods

QualifiersMethod
Date(args: Array)
 Construct a new date object.
format(layout: String): String
 Format a date using a format specifier in local time.
formatUTC(layout: String): String
 Format a date using a format specifier in UTC time.
getHours(): Number
 Return the hour (0 - 23) in local time.
getUTCMinutes(): Number
 Return the minute (0 - 59) in UTC time.
getUTCMonth(): Number
 Return the month (1 - 12) in UTC time.
future(msec: Number): Date
 Calculate a time that is msec in the future.
getDate(): Number
 Return the day of the month in local time.
getDay(): Number
 Return the day of the week in local time.
getFullYear(): Number
 Return the year as four digits in local time.
getUTCSeconds(): Number
 Return the second (0 - 59) in UTC time.
getMilliseconds(): Number
 Return the millisecond (0 - 999) in local time.
getMinutes(): Number
 Return the minute (0 - 59) in local time.
getMonth(): Number
 Return the month (0 - 11) in local time.
getSeconds(): Number
 Return the second (0 - 59) in local time.
getTime(): Number
 Return the number of milliseconds since midnight, January 1st, 1970 UTC.
getTimezoneOffset(): Number
 Return the number of minutes between the local computer time and Coordinated Universal Time.
getUTCDate(): Number
 Return the day (date) of the month (1 - 31) in UTC time.
getUTCDay(): Number
 Return the day of the week (0 - 6) in UTC time.
getUTCFullYear(): Number
 Return the year in UTC time.
getUTCHours(): Number
 Return the hour (0 - 23) in UTC time.
getUTCMilliseconds(): Number
 Return the millisecond (0 - 999) in UTC time.
nanoAge(): Number
 Time in nanoseconds since the date object was constructed.
nextDay(inc: Number = 1): Date
 Return a new Date object that is one day greater than this one.
setDate(d: Number): Void
 Set the date of the month (1 - 31) If a value outside the range is given, the date is adjusted without error.
setFullYear(y: Number): Void
 Set the current year as four digits in local time.
setHours(h: Number): Void
 Set the current hour (0 - 23) in local time.
setMilliseconds(ms: Number): Void
 Set the current millisecond (0 - 999) in local time.
setMinutes(min: Number): Void
 Set the current minute (0 - 59) in local time.
setMonth(mon: Number): Void
 Set the current month (0 - 11) in local time.
setSeconds(sec: Number, msec: Number = null): Void
 Set the current second (0 - 59) in local time.
setTime(value: Number): Void
 Set the number of milliseconds since midnight, January 1st, 1970 UTC.
setUTCDate(d: Number): Void
 Set the date of the month (1 - 31) in UTC time.
setUTCFullYear(y: Number): Void
 Set the current year as four digits in UTC time.
setUTCHours(h: Number): Void
 Set the current hour (0 - 23) in UTC time.
setUTCMilliseconds(ms: Number): Void
 Set the current millisecond (0 - 999) in UTC time.
setUTCMinutes(min: Number): Void
 Set the current minute (0 - 59) in UTC time.
setUTCMonth(mon: Number): Void
 Set the current month (0 - 11) in UTC time.
setUTCSeconds(sec: Number, msec: Number = null): Void
 Set the current second (0 - 59) in UTC time.
toDateString(): String
 Return a string containing the date portion excluding the time portion of the date in local time.
toISOString(): String
 Return an ISO formatted date string.
override toJSON(): String
 Convert a date to an equivalent JSON encoding.
toLocaleDateString(): String
 Return a localized string containing the date portion excluding the time portion of the date in local time.
override toLocaleString(): String
 Return a localized string containing the date.
toLocaleTimeString(): String
 Return a string containing the time portion of the date in local time.
override toString(): String
 Return a string representing the date in local time.
toTimeString(): String
 Return a string containing the time portion in human readable form in American English.
toUTCString(): String
 Return a string containing the date in UTC time.
override valueOf(): Number
 Return the primitive value of the object.

Method Detail

Date(args: Array)
Description
Construct a new date object. Permissible constructor forms:
  • Date() This is the default and it constructs a date instance for the current time.
  • Date(milliseconds) where (seconds sincde 1 Jan 1970 00:00:00 UTC))
  • Date(dateString) where (In a format recognized by parse())
  • Date(year, month, date) where (Four digit year, month: 0-11, date: 1-31)
  • Date(year, month, date [, hour, minute, second, msec]) where (hour: 0-23, minute: 0-59, second: 0-59, msec: 0-999)

static UTC(year: Number, month: Number, day: Number, hours: Number = 0, minutes: Number = 0, seconds: Number = 0, milliseconds: Number = 0): Number
Description
Calculate the number of milliseconds since the epoch for a UTC time. Date(year, month, date [, hour, minute, second, msec])
Parameters
year: Number Year.
month: Number Month of year.
day: Number Day of month.
hours: Number Hour of day. [default: 0]
minutes: Number Minute of hour. [default: 0]
seconds: Number Secods of minute. [default: 0]
milliseconds: Number Milliseconds of second. [default: 0]
Returns
The number of milliseconds since January 1, 1970 00:00:00 UTC.

format(layout: String): String
Description
Format a date using a format specifier in local time. This routine is implemented by calling the O/S strftime routine and so not all the format specifiers are available on all platforms. For full details, consult your platform API manual for strftime.

The format specifiers are:
  • %A national representation of the full weekday name.
  • %a national representation of the abbreviated weekday name.
  • %B national representation of the full month name.
  • %b national representation of the abbreviated month name.
  • %C (year / 100) as decimal number; single digits are preceded by a zero..
  • %c national representation of time and date.
  • %D is equivalent to %m/%d/%y.
  • %d the day of the month as a decimal number (01-31).
  • %e the day of month as a decimal number (1-31); single digits are preceded by a blank.
  • %F is equivalent to %Y-%m-%d.
  • %H the hour (24-hour clock) as a decimal number (00-23).
  • %h the same as %b.
  • %I the hour (12-hour clock) as a decimal number (01-12).
  • %j the day of the year as a decimal number (001-366). Note: this range is different to that of the dayOfYear property which is 0-365.
  • %k the hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a blank.
  • %l the hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a blank.
  • %M the minute as a decimal number (00-59).
  • %m the month as a decimal number (01-12).
  • %n a newline.
  • %P Lower case national representation of either "ante meridiem" or "post meridiem" as appropriate.
  • %p national representation of either "ante meridiem" or "post meridiem" as appropriate.
  • %R is equivalent to %H:%M.
  • %r is equivalent to %I:%M:%S %p.
  • %S the second as a decimal number (00-60).
  • %s the number of seconds since the January 1, 1970 UTC.
  • %T is equivalent to %H:%M:%S.
  • %t a tab.
  • %U the week number of the year (Sunday as the first day of the week) as a decimal number (00-53).
  • %u the weekday (Monday as the first day of the week) as a decimal number (1-7).
  • %v is equivalent to %e-%b-%Y.
  • %W the week number of the year (Monday as the first day of the week) as a decimal number (00-53).
  • %w the weekday (Sunday as the first day of the week) as a decimal number (0-6).
  • %X national representation of the time.
  • %x national representation of the date.
  • %Y the year with century as a decimal number.
  • %y the year without century as a decimal number (00-99).
  • %Z the time zone name.
  • %z the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers).
  • %+ national representation of the date and time (the format is similar to that produced by date(1)). This format is platform dependent.
  • %% Literal percent.


Some platforms may also support the following format extensions:
  • %E* POSIX locale extensions. Where "*"" is one of the characters: c, C, x, X, y, Y.
  • %G a year as a decimal number with century. This year is the one that contains the greater part of the week (Monday as the first day of the week).
  • %g the same year as in %G, but as a decimal number without century (00-99).
  • %O* POSIX locale extensions. Where "*"" is one of the characters: d e H I m M S u U V w W y. supposed to provide alternate representations. Additionly %OB implemented to represent alternative months names (used standalone, without day mentioned).
  • %V the week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1.
Parameters
layout: String Format layout string using the above format specifiers. See strftime(3) for more information.
Returns
String representation of the date.
Specified
ejscript-2.5

formatUTC(layout: String): String
Description
Format a date using a format specifier in UTC time. This routine is implemented by calling the O/S strftime routine and so not all the format specifiers are available on all platforms.
Parameters
layout: String Format layout string using the above format specifiers. See format() for the list of format specifiers.
Returns
String representation of the date.
Specified
ejscript-2.5

getHours(): Number
Description
Return the hour (0 - 23) in local time.
Returns
The integer hour of the day (.

getUTCMinutes(): Number
Description
Return the minute (0 - 59) in UTC time.
Returns
The number of minutes as an integer 8.

getUTCMonth(): Number
Description
Return the month (1 - 12) in UTC time.
Returns
The month number as an integer.

future(msec: Number): Date
Description
Calculate a time that is msec in the future.
Parameters
msec: Number Period into the future in milliseconds. Can be negative for the past.
Returns
A new date object.

getDate(): Number
Description
Return the day of the month in local time.
Returns
Returns the day of the year (1-31).

getDay(): Number
Description
Return the day of the week in local time.
Returns
The integer day of the week (0 - 6, where 0 is Sunday).

getFullYear(): Number
Description
Return the year as four digits in local time.
Returns
The integer year.

getUTCSeconds(): Number
Description
Return the second (0 - 59) in UTC time.
Returns
The number of seconds as an integer 8.

getMilliseconds(): Number
Description
Return the millisecond (0 - 999) in local time.
Returns
The number of milliseconds as an integer.

getMinutes(): Number
Description
Return the minute (0 - 59) in local time.
Returns
The number of minutes as an integer.

getMonth(): Number
Description
Return the month (0 - 11) in local time.
Returns
The month number as an integer.

getSeconds(): Number
Description
Return the second (0 - 59) in local time.
Returns
The number of seconds as an integer.

getTime(): Number
Description
Return the number of milliseconds since midnight, January 1st, 1970 UTC.
Returns
The number of milliseconds as a long.

getTimezoneOffset(): Number
Description
Return the number of minutes between the local computer time and Coordinated Universal Time.
Returns
Integer containing the number of minutes between UTC and local time. The offset is positive if local time is behind UTC and negative if it is ahead. E.g. American PST is UTC-8 so 480 will be retured. This value will vary if daylight savings time is in effect.

getUTCDate(): Number
Description
Return the day (date) of the month (1 - 31) in UTC time.
Returns
The day of the month as an integer 0.

getUTCDay(): Number
Description
Return the day of the week (0 - 6) in UTC time.
Returns
The day of the week as an integer.

getUTCFullYear(): Number
Description
Return the year in UTC time.
Returns
The full year in 4 digits as an integer.

getUTCHours(): Number
Description
Return the hour (0 - 23) in UTC time.
Returns
The integer hour of the day.

getUTCMilliseconds(): Number
Description
Return the millisecond (0 - 999) in UTC time.
Returns
The number of milliseconds as an integer.

nanoAge(): Number
Description
Time in nanoseconds since the date object was constructed.
Specified
ejs (

nextDay(inc: Number = 1): Date
Description
Return a new Date object that is one day greater than this one.
Parameters
inc: Number Increment in days to add (or subtract if negative). [default: 1]
Returns
A Date object.
Specified
ejscript-2.5

static now(): Number
Description
Return the current time as milliseconds since Jan 1 1970. This returns the same value as date.time for instances.
Specified
mozilla 0

static parse(dateString: String): Number
Description
Parse a date string and return the number of milliseconds since midnight, January 1st, 1970 UTC. If dateString does not contain a timezone, the date string will be interpreted as a local date/time.
Parameters
dateString: String The string to parse. See parseDate for supported formats.
Returns
Return a new date number.

static parseDate(dateString: String, defaultDate: Date = null): Date
Description
Parse a date string and Return a new Date object. If dateString does not contain a timezone, the date string will be interpreted as a local date/time. This is similar to parse() but it returns a date object.
Parameters
dateString: String The date string to parse. The date parsing logic uses heuristics and attempts to intelligently parse a range of dates. Some of the possible formats are:
  • 07/28/2014
  • 07/28/08
  • Jan/28/2014
  • Jaunuary-28-2014
  • 28-jan-2014
  • [29] Jan [15] [2014]
  • dd/mm/yy, dd.mm.yy, dd-mm-yy
  • mm/dd/yy, mm.dd.yy, mm-dd-yy
  • yyyy/mm/dd, yyyy.mm.dd, yyyy-mm-dd
  • 10:52[:23]
  • 2009-05-21t16:06:05.000z (ISO date)
  • [GMT|UTC][+-]NN[:]NN (timezone)
defaultDate: Date Default date to use to fill out missing items in the date string. [default: null]
Returns
Return a new Date.
Specified
ejscript-2.5

static parseUTCDate(dateString: String, defaultDate: Date = null): Date
Description
Parse a date string and Return a new Date object. If dateString does not contain a timezone, the date string will be interpreted as a UTC date/time.
Parameters
dateString: String UTC date string to parse. See parseDate for supported formats.
defaultDate: Date Default date to use to fill out missing items in the date string. [default: null]
Returns
Return a new Date.
Specified
ejscript-2.5

setDate(d: Number): Void
Description
Set the date of the month (1 - 31) If a value outside the range is given, the date is adjusted without error.
Parameters
d: Number Date of the month.

setFullYear(y: Number): Void
Description
Set the current year as four digits in local time.
Parameters
y: Number Current year.

setHours(h: Number): Void
Description
Set the current hour (0 - 23) in local time. If a value outside the range is given, the date is adjusted without error.
Parameters
h: Number The hour as an integer 0.

setMilliseconds(ms: Number): Void
Description
Set the current millisecond (0 - 999) in local time. If a value outside the range is given, the date is adjusted without error.
Parameters
ms: Number The millisecond as an integer 8.

setMinutes(min: Number): Void
Description
Set the current minute (0 - 59) in local time. If a value outside the range is given, the date is adjusted without error.
Parameters
min: Number The minute as an integer.

setMonth(mon: Number): Void
Description
Set the current month (0 - 11) in local time. If a value outside the range is given, the date is adjusted without error.
Parameters
mon: Number The month as an integer.

setSeconds(sec: Number, msec: Number = null): Void
Description
Set the current second (0 - 59) in local time. If a value outside the range is given, the date is adjusted without error.
Parameters
sec: Number The second as an integer.
msec: Number Optional milliseconds as an integer. [default: null]

setTime(value: Number): Void
Description
Set the number of milliseconds since midnight, January 1st, 1970 UTC.
Parameters
value: Number The millisecond as a long.

setUTCDate(d: Number): Void
Description
Set the date of the month (1 - 31) in UTC time. If a value outside the range is given, the date is adjusted without error.
Parameters
d: Number The date to set.

setUTCFullYear(y: Number): Void
Description
Set the current year as four digits in UTC time.
Parameters
y: Number The year to set.

setUTCHours(h: Number): Void
Description
Set the current hour (0 - 23) in UTC time. If a value outside the range is given, the date is adjusted without error.
Parameters
h: Number The hour as an integer.

setUTCMilliseconds(ms: Number): Void
Description
Set the current millisecond (0 - 999) in UTC time. If a value outside the range is given, the date is adjusted without error.
Parameters
ms: Number The millisecond as an integer.

setUTCMinutes(min: Number): Void
Description
Set the current minute (0 - 59) in UTC time. If a value outside the range is given, the date is adjusted without error.
Parameters
min: Number The minute as an integer.

setUTCMonth(mon: Number): Void
Description
Set the current month (0 - 11) in UTC time. If a value outside the range is given, the date is adjusted without error.
Parameters
mon: Number The month as an integer.

setUTCSeconds(sec: Number, msec: Number = null): Void
Description
Set the current second (0 - 59) in UTC time. If a value outside the range is given, the date is adjusted without error.
Parameters
sec: Number The second as an integer.
msec: Number Optional milliseconds as an integer P. [default: null]

toDateString(): String
Description
Return a string containing the date portion excluding the time portion of the date in local time. The format is American English. Sample: "Fri Jan 15 2014".
Returns
A string representing the date portion. 0.

toISOString(): String
Description
Return an ISO formatted date string. Sample: "2006-12-15T23:45:09.33-08:00".
Returns
An ISO formatted string representing the date.
Specified
ejscript-2.5

override toJSON(): String
Description
Convert a date to an equivalent JSON encoding.
Returns
This function returns a date in ISO format as a string.
Throws
TypeError: If the object could not be converted to a string.

toLocaleDateString(): String
Description
Return a localized string containing the date portion excluding the time portion of the date in local time. Note: You should not rely on the format of the output as the exact format will depend on the platform and locale. Sample: "Fri 15 Dec 2006 GMT-0800". (Note: Other platforms render as: V8 format: "Fri, 15 Dec 2006 GMT-0800" JS format: "01/15/2014" JSC format: "January 15, 2014").
Returns
A string representing the date portion.

override toLocaleString(): String
Description
Return a localized string containing the date. This formats the date using the operating system's locale conventions. Sample: "Fri 15 Dec 2006 23:45:09 GMT-0800 (PST)". (Note: Other JavaScript platforms render as: V8 format: "Fri, 15 Dec 2006 23:45:09 GMT-0800 (PST)" JS format: "Fri Jan 15 13:09:02 2014" JSC format: "January 15, 2014 1:09:06 PM PST".
Returns
A string representing the date.

toLocaleTimeString(): String
Description
Return a string containing the time portion of the date in local time. Sample: "13:08:57". Note: Other JavaScript platforms render as: V8 format: "13:08:57" JS format: "13:09:02" JSC format: "1:09:06 PM PST".
Returns
A string representing the time.

override toString(): String
Description
Return a string representing the date in local time. The format is American English. Sample: "Fri 15 Dec 2006 23:45:09 GMT-0800 (PST)".
Returns
A string representing the date.

toTimeString(): String
Description
Return a string containing the time portion in human readable form in American English. Sample: "13:08:57 GMT-0800 (PST)".
Returns
A string representing the time.

toUTCString(): String
Description
Return a string containing the date in UTC time. Sample: "Sat, 16 Dec 2006 08:06:21 GMT".
Returns
A string representing the date.

override valueOf(): Number
Description
Return the primitive value of the object.
Returns
A number corresponding to the time property.