Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Date

Add some helpful methods for Date.prototype

Hierarchy

  • Date

Index

Methods

add

  • add(v: number, type: "ms" | "s" | "m" | "h" | "d" | "w" | "M" | "y"): Date
  • Adds value to this date by millisecond | second | minute | hour | day | week | month | year

    Parameters

    • v: number
    • type: "ms" | "s" | "m" | "h" | "d" | "w" | "M" | "y"

    Returns Date

between

  • between(start: Date, end: Date): boolean
  • Determines if this instance is between a range of two dates or equal to either the start or end dates.

    Parameters

    • start: Date

      Start of range [Required]

    • end: Date

      End of range [Required]

    Returns boolean

    true is this is between or equal to the start and end dates, else false

clone

  • Returns a new Date object that is an exact date and time copy of the original instance.

    Returns Date

    A new Date instance

diff

  • diff(date?: Date): number
  • Returns the number of milliseconds between this date and date.

    Parameters

    • Optional date: Date

      Defaults to now

    Returns number

    The diff in milliseconds

equals

  • equals(date: Date, type?: "ms" | "s" | "m" | "h" | "d" | "w" | "M" | "y"): boolean
  • Compares this instance to another Date object and returns true if they are equal.

    Parameters

    • date: Date

      Date object to compare. If no date to compare, new Date() [now] is used.

    • Optional type: "ms" | "s" | "m" | "h" | "d" | "w" | "M" | "y"

    Returns boolean

    true if dates are equal. false if they are not equal.

format

  • format(format?: string, locale?: Locale): string
  • Converts the value of the current Date object to its equivalent string representation.

    Format Specifiers:

    https://www.w3.org/TR/NOTE-datetime
    https://www.ietf.org/rfc/rfc3339.txt
    

    Formats:

    Format  Description                                              Example
    ------  -------------------------------------------------------  ----------------
    s      The seconds of the minute between 0-59.                   "0" to "59"
    ss     The seconds of the minute with leading zero if required.  "00" to "59"
    
    m      The minute of the hour between 0-59.                      "0"  or "59"
    mm     The minute of the hour with leading zero if required.     "00" or "59"
    
    h      The hour of the day between 1-12.                         "1"  to "12"
    hh     The hour of the day with leading zero if required.        "01" to "12"
    
    H      The hour of the day between 0-23.                         "0"  to "23"
    HH     The hour of the day with leading zero if required.        "00" to "23"
    
    ddd    Abbreviated week day name.                                "Mon" to "Sun"
    dddd   The full week day name.                                   "Monday" to "Sunday"
    
    D      The day of the month between 1 and 31.                    "1"  to "31"
    DD     The day of the month with leading zero if required.       "01" to "31"
    
    M      The month of the year between 1-12.                       "1" to "12"
    MM     The month of the year with leading zero if required.      "01" to "12"
    MMM    Abbreviated month name.                                   "Jan" to "Dec"
    MMMM   The full month name.                                      "January" to "December"
    
    YY     The year as a two-digit number.                           "99" or "08"
    YYYY   The full four digit year.                                 "1999" or "2008"
    
    A      AM or PM                                                  "AM" or "PM"
    

    Parameters

    • Optional format: string

      A format string. The default value is: 'YYYY-MM-DD HH:mm:ss'.

    • Optional locale: Locale

      A local string like {language}-{country}.

    Returns string

    A string representation of the current Date object.

formatTimezoneOffset

  • formatTimezoneOffset(): string
  • Get the timezone offset string of the date.

    Returns string

    The 4-character offset string prefixed with + or - (e.g. "-0500")

getWeek

  • getWeek(): number
  • Returns number

    1~53

isAfter

  • isAfter(date: Date): boolean
  • Determines if this date occurs after the date to compare to.

    Parameters

    • date: Date

      Date object to compare. If no date to compare, new Date() ("now") is used.

    Returns boolean

    true if this date instance is greater than the date to compare to (or "now"), otherwise false.

isBefore

  • isBefore(date: Date): boolean
  • Determines if this date occurs before the date to compare to.

    Parameters

    • date: Date

      Date object to compare. If no date to compare, new Date() ("now") is used.

    Returns boolean

    true if this date instance is less than the date to compare to (or "now").

isToday

  • isToday(date: Date): boolean
  • if this date instance is 'today', otherwise false.

    Parameters

    Returns boolean

set

  • set(config: { day?: number; hour?: number; millisecond?: number; minute?: number; month?: number; second?: number; timezoneOffset?: number; week?: number; year?: number }): Date
  • Sets new value to this date on millisecond | second | minute | hour | day | week | month | year | timezoneOffset

    Parameters

    • config: { day?: number; hour?: number; millisecond?: number; minute?: number; month?: number; second?: number; timezoneOffset?: number; week?: number; year?: number }
      • Optional day?: number
      • Optional hour?: number
      • Optional millisecond?: number
      • Optional minute?: number
      • Optional month?: number
      • Optional second?: number
      • Optional timezoneOffset?: number
      • Optional week?: number
      • Optional year?: number

    Returns Date

setLastTime

  • setLastTime(): Date
  • Resets the time of this Date object to 23:59:59:999, which is the end of the day.

    Returns Date

    this

setNowTime

  • setNowTime(): Date
  • Resets the time of this Date object to the current time ('now').

    Returns Date

    this

setTimezoneOffset

  • setTimezoneOffset(offset: number): Date
  • Sets new timezone offset(Minutes) to this date.

    Parameters

    • offset: number

    Returns Date

setWeek

  • setWeek(week: number, dayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6): Date
  • Moves the date to the week set. Week one (1) is the week which contains the first day of the year.

    Parameters

    • week: number

      A Number (1 to 53) that represents the week of the year.

    • Optional dayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6

      0 is Sunday, Defaults is 1.

    Returns Date

    this

setZeroTime

  • setZeroTime(): Date
  • Resets the time of this Date object to 00:00:00:000, which is the start of the day.

    Returns Date

    this