Class Date

Index

Properties

Methods

Properties

public static DAY: string

[Property] (String)

public static HOUR: string

[Property] (String)

public static MILLI: string

[Property] (String)

public static MINUTE: string

[Property] (String)

public static MONTH: string

[Property] (String)

public static SECOND: string

[Property] (String)

public static YEAR: string

[Property] (String)

public static dayNames: Array<any>

[Property] (Array)

public static defaultFormat: string

[Property] (String)

public static defaults: any

[Property] (Object)

public static formatCodes: any

[Property] (Object)

public static formatFunctions: any

[Property] (Object)

public static monthNames: Array<any>

[Property] (Array)

public static monthNumbers: any

[Property] (Object)

public static parseFunctions: any

[Property] (Object)

public static useStrict: boolean

[Property] (Boolean)

Methods

public static add(date?: any, interval?: string, value?: number): any

[Method] Provides a convenient method for performing basic date arithmetic

Parameters

  • date?: any optional

    Date The date to modify.

  • interval?: string optional

    String A valid date interval enum value.

  • value?: number optional

    Number The amount to add to the current date.

Returns

any

Date The new Date instance.

public static align(date?: any, unit?: string): any

[Method] Align the date to unit

Parameters

  • date?: any optional

    Date The date to be aligned.

  • unit?: string optional

    String The unit. This unit is compatible with the date interval constants.

Returns

any

Date The aligned date.

public static between(date?: any, start?: any, end?: any): boolean

[Method] Checks if a date falls on or between the given start and end dates

Parameters

  • date?: any optional

    Date The date to check.

  • start?: any optional

    Date Start date.

  • end?: any optional

    Date End date.

Returns

boolean

Boolean true if this date falls on or between the given start and end dates.

public static clearTime(date?: any, clone?: boolean): any

[Method] Attempts to clear all time information from this Date by setting the time to midnight of the same day automatically

Parameters

  • date?: any optional

    Date The date.

  • clone?: boolean optional

    Boolean true to create a clone of this date, clear the time and return it.

Returns

any

Date this or the clone.

public static clone(date?: any): any

[Method] Creates and returns a new Date instance with the exact same date value as the called instance

Parameters

  • date?: any optional

    Date The date.

Returns

any

Date The new Date instance.

public static diff(min?: any, max?: any, unit?: string): number

[Method] Calculate how many units are there between two time

Parameters

  • min?: any optional

    Date The first time.

  • max?: any optional

    Date The second time.

  • unit?: string optional

    String The unit. This unit is compatible with the date interval constants.

Returns

number

Number The maximum number n of units that min + n * unit <= max.

public static format(date?: any, format?: string): string

[Method] Formats a date given the supplied format string

Parameters

  • date?: any optional

    Date The date to format.

  • format?: string optional

    String The format string.

Returns

string

String The formatted date.

public static getDayOfYear(date?: any): number

[Method] Get the numeric day number of the year adjusted for leap year

Parameters

  • date?: any optional

    Date The date.

Returns

number

Number 0 to 364 (365 in leap years).

public static getDaysInMonth(date?: any): number

[Method] Get the number of days in the current month adjusted for leap year

Parameters

  • date?: any optional

    Date The date.

Returns

number

Number The number of days in the month.

public static getElapsed(dateA?: any, dateB?: any): number

[Method] Returns the number of milliseconds between two dates

Parameters

  • dateA?: any optional

    Date The first date.

  • dateB?: any optional

    Date The second date, defaults to now.

Returns

number

Number The difference in milliseconds.

public static getFirstDateOfMonth(date?: any): any

[Method] Get the date of the first day of the month in which this date resides

Parameters

  • date?: any optional

    Date The date.

Returns

any

Date

public static getFirstDayOfMonth(date?: any): number

[Method] Get the first day of the current month adjusted for leap year

Parameters

  • date?: any optional

    Date The date

Returns

number

Number The day number (0-6).

public static getGMTOffset(date?: any, colon?: boolean): string

[Method] Get the offset from GMT of the current date equivalent to the format specifier O

Parameters

  • date?: any optional

    Date The date.

  • colon?: boolean optional

    Boolean true to separate the hours and minutes with a colon.

Returns

string

String The 4-character offset string prefixed with + or - (e.g. '-0600').

public static getLastDateOfMonth(date?: any): any

[Method] Get the date of the last day of the month in which this date resides

Parameters

  • date?: any optional

    Date The date.

Returns

any

Date

public static getLastDayOfMonth(date?: any): number

[Method] Get the last day of the current month adjusted for leap year

Parameters

  • date?: any optional

    Date The date.

Returns

number

Number The day number (0-6).

public static getMonthNumber(name?: string): number

[Method] Get the zero based JavaScript month number for the given short full month name

Parameters

  • name?: string optional

    String The short/full month name.

Returns

number

Number The zero-based JavaScript month number.

public static getShortDayName(day?: number): string

[Method] Get the short day name for the given day number

Parameters

  • day?: number optional

    Number A zero-based JavaScript day number.

Returns

string

String The short day name.

public static getShortMonthName(month?: number): string

[Method] Get the short month name for the given month number

Parameters

  • month?: number optional

    Number A zero-based JavaScript month number.

Returns

string

String The short month name.

public static getSuffix(date?: any): string

[Method] Get the English ordinal suffix of the current day equivalent to the format specifier S

Parameters

  • date?: any optional

    Date The date.

Returns

string

String 'st', 'nd', 'rd' or 'th'.

public static getTimezone(date?: any): string

[Method] Get the timezone abbreviation of the current date equivalent to the format specifier T

Parameters

  • date?: any optional

    Date The date.

Returns

string

String The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).

public static getWeekOfYear(date?: any): number

[Method] Get the numeric ISO 8601 week number of the year equivalent to the format specifier W but without a leading zero

Parameters

  • date?: any optional

    Date The date.

Returns

number

Number 1 to 53.

public static isDST(date?: any): boolean

[Method] Checks if the current date is affected by Daylight Saving Time DST

Parameters

  • date?: any optional

    Date The date.

Returns

boolean

Boolean true if the current date is affected by DST.

public static isLeapYear(date?: any): boolean

[Method] Checks if the current date falls within a leap year

Parameters

  • date?: any optional

    Date The date.

Returns

boolean

Boolean true if the current date falls within a leap year, false otherwise.

public static isValid(year?: number, month?: number, day?: number, hour?: number, minute?: number, second?: number, millisecond?: number): boolean

[Method] Checks if the passed Date parameters will cause a JavaScript Date rollover

Parameters

  • year?: number optional

    Number 4-digit year.

  • month?: number optional

    Number 1-based month-of-year.

  • day?: number optional

    Number Day of month.

  • hour?: number optional

    Number Hour.

  • minute?: number optional

    Number Minute.

  • second?: number optional

    Number Second.

  • millisecond?: number optional

    Number Millisecond.

Returns

boolean

Boolean true if the passed parameters do not cause a Date "rollover", false otherwise.

public static now(): number

[Method] Returns the current timestamp

Returns

number

Number The current timestamp.

public static parse(input?: string, format?: string, strict?: boolean): any

[Method] Parses the passed string using the specified date format

Parameters

  • input?: string optional

    String The raw date string.

  • format?: string optional

    String The expected date string format.

  • strict?: boolean optional

    Boolean true to validate date strings while parsing (i.e. prevents JavaScript Date "rollover"). Invalid date strings will return null when parsed.

Returns

any

Date/null The parsed Date, or null if an invalid date string.