Class Date

Index

Properties

Methods

Properties

public dateRegEx: string

APIProperty: dateRegEx The regex to be used for validating dates. You can provide your own regex for instance for adding support for years before BC. Default value is: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/

Methods

public parse(str: string): Date

APIMethod: parse Generate a date object from a string. The format for the string follows the profile of ISO 8601 for date and time on the Internet (see http://tools.ietf.org/html/rfc3339). We don't call the native Date.parse because of inconsistency between implmentations. In Chrome, calling Date.parse with a string that doesn't contain any indication of the timezone (e.g. "2011"), the date is interpreted in local time. On Firefox, the assumption is UTC.

Parameters: str - {String} A string representing the date (e.g. "2010", "2010-08", "2010-08-07", "2010-08-07T16:58:23.123Z", "2010-08-07T11:58:23.123-06").

Returns: {Date} A date object. If the string could not be parsed, an invalid date is returned (i.e. isNaN(date.getTime())).

Parameters

  • str: string

Returns

Date

public toISOString(date: Date): string

APIMethod: toISOString Generates a string representing a date. The format of the string follows the profile of ISO 8601 for date and time on the Internet (see http://tools.ietf.org/html/rfc3339). If the toISOString method is available on the Date prototype, that is used. The toISOString method for Date instances is defined in ECMA-262.

Parameters: date - {Date} A date object.

Returns: {String} A string representing the date (e.g. "2010-08-07T16:58:23.123Z"). If the date does not have a valid time (i.e. isNaN(date.getTime())) this method returns the string "Invalid Date". The ECMA standard says the toISOString method should throw RangeError in this case, but Firefox returns a string instead. For best results, use isNaN(date.getTime()) to determine date validity before generating date strings.

Parameters

Returns

string