Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DateTime

Represents an instant in time, typically expressed as a date and time of day.

Hierarchy

  • DateTime

Index

Constructors

constructor

  • new DateTime(): DateTime
  • new DateTime(ticks: number): DateTime
  • new DateTime(date: Date): DateTime
  • new DateTime(year: number, month: number, day: number): DateTime
  • new DateTime(year: number, month: number, day: number, hour: number, minute: number, second: number): DateTime
  • new DateTime(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number): DateTime
  • new DateTime(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number): DateTime
  • Initializes a new instance of the DateTime to the current date and time.

    Returns DateTime

  • Initializes a new instance of the DateTime to a specified number of ticks.

    Parameters

    • ticks: number

      A date and time expressed in the number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000 in the Gregorian calendar.

    Returns DateTime

  • Initializes a new instance of the DateTime to the current date and time. Initializes a new instance of the DateTime to a specified number of ticks. Initializes a new instance of the DateTime to the specified year, month, and day. Initializes a new instance of the DateTime to the specified year, month, day, hour, minute, and second. Initializes a new instance of the DateTime to the specified year, month, day, hour, minute, second, and millisecond.

    Parameters

    • date: Date

    Returns DateTime

  • Initializes a new instance of the DateTime to the specified year, month, and day.

    Parameters

    • year: number

      The year (1 through 9999).

    • month: number

      The month (1 through 12).

    • day: number

      The day (1 through the number of days in month).

    Returns DateTime

  • Initializes a new instance of the DateTime to the specified year, month, day, hour, minute, and second.

    Parameters

    • year: number

      The year (1 through 9999).

    • month: number

      The month (1 through 12).

    • day: number

      The day (1 through the number of days in month).

    • hour: number

      The hours (0 through 23).

    • minute: number

      The minutes (0 through 59).

    • second: number

      The seconds (0 through 59).

    Returns DateTime

  • Initializes a new instance of the DateTime to the specified year, month, day, hour, minute, second, and millisecond.

    Parameters

    • year: number

      The year (1 through 9999).

    • month: number

      The month (1 through 12).

    • day: number

      The day (1 through the number of days in month).

    • hour: number

      The hours (0 through 23).

    • minute: number

      The minutes (0 through 59).

    • second: number

      The seconds (0 through 59).

    • millisecond: number

      The milliseconds (0 through 999).

    Returns DateTime

  • Initializes a new instance of the DateTime to the current date and time. Initializes a new instance of the DateTime to a specified number of ticks. Initializes a new instance of the DateTime to the specified year, month, and day. Initializes a new instance of the DateTime to the specified year, month, day, hour, minute, and second. Initializes a new instance of the DateTime to the specified year, month, day, hour, minute, second, and millisecond.

    Parameters

    • year: number

      The year (1 through 9999).

    • month: number

      The month (1 through 12).

    • day: number

      The day (1 through the number of days in month).

    • hour: number

      The hours (0 through 23).

    • minute: number

      The minutes (0 through 59).

    • second: number

      The seconds (0 through 59).

    • millisecond: number

      The milliseconds (0 through 999).

    Returns DateTime

Accessors

day

  • get day(): number
  • The day-of-month part of this DateTime. The value is between 1 and 31.

    Returns number

dayOfWeek

  • The day-of-week part of this DateTime. The returned value is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates Thursday, 5 indicates Friday, and 6 indicates Saturday.

    Returns DayOfWeek

dayOfYear

  • get dayOfYear(): number
  • The day-of-year part of this DateTime. The value is between 1 and 366.

    Returns number

hour

  • get hour(): number
  • The hour part of this DateTime. The value is between 0 and 23.

    Returns number

millisecond

  • get millisecond(): number
  • The millisecond part of this DateTime. The value is between 0 and 999.

    Returns number

minute

  • get minute(): number
  • The minute part of this DateTime. The value is between 0 and 59.

    Returns number

month

  • get month(): number
  • The month part of this DateTime. The value is an integer between 1 and 12.

    Returns number

second

  • get second(): number
  • The second part of this DateTime. The value is between 0 and 59.

    Returns number

ticks

  • get ticks(): number
  • Returns the tick count for this DateTime. The returned value is the number of 100-nanosecond intervals that have elapsed since 1/1/0001 12:00am.

    Returns number

year

  • get year(): number
  • The year part of this DateTime. The value is between 1 and 9999.

    Returns number

Methods

addDays

  • Adds a fractional number of days to this DateTime. The result is computed by rounding the fractional number of days given by value to the nearest millisecond, and adding that interval to this DateTime. The value argument is permitted to be negative.

    Parameters

    • value: number

      The number of days to add.

    Returns DateTime

addHours

  • Add a fractional number of hours to this DateTime. The result is computed by rounding the fractional number of hours given by value to the nearest millisecond, and adding that interval to this DateTime. The value argument is permitted to be negative.

    Parameters

    • value: number

      The number of hours to add.

    Returns DateTime

addMilliseconds

  • addMilliseconds(value: number): DateTime
  • Add a given number of milliseconds to this DateTime. The result is computed by rounding the number of milliseconds given by value to the nearest integer, and adding that interval to this DateTime. The value argument is permitted to be negative.

    Parameters

    • value: number

      The number of milliseconds to add.

    Returns DateTime

addMinutes

  • Add a fractional number of minutes to this DateTime. The result is computed by rounding the fractional number of minutes given by value to the nearest millisecond, and adding that interval to this DateTime. The value argument is permitted to be negative.

    Parameters

    • value: number

      The number of fractional minutes to add.

    Returns DateTime

addMonths

  • Adds the given number of months to this DateTime. The result is computed by incrementing (or decrementing) the year and month parts of this DateTime by months, and, if required, adjusting the day part of the resulting date downwards to the last day of the resulting month in the resulting year. The time-of-day part of the result is the same as the time-of-day part of this DateTime.

    In more precise terms, considering this DateTime to be of the form y / m / d + t, where y is the year, m is the month, d is the day, and t is the time-of-day, the result is y1 / m1 / d1 + t, where y1 and m1 are computed by adding months months to y and m, and d1 is the largest value less than or equal to d that denotes a valid day in month m1 of year y1.

    Parameters

    • months: number

      The number of months to add.

    Returns DateTime

addSeconds

  • Adds a fractional number of seconds to this DateTime. The result is computed by rounding the fractional number of seconds given by value to the nearest millisecond, and adding that interval to this DateTime. The value argument is permitted to be negative.

    Parameters

    • value: number

    Returns DateTime

addTicks

  • Add the given number of 100-nanosecond ticks to this DateTime. The value argument is permitted to be negative.

    Parameters

    • value: number

      the number of ticks to add.

    Returns DateTime

addYears

  • Add the given number of years to this DateTime. The result is computed by incrementing (or decrementing) the year part of this DateTime by value years. If the month and day of this DateTime is 2/29, and if the resulting year is not a leap year, the month and day of the resulting DateTime becomes 2/28. Otherwise, the month, day, and time-of-day parts of the result are the same as those of this DateTime.

    Parameters

    • value: number

      The number of years to add.

    Returns DateTime

compareTo

  • Compares two DateTimes.

    Parameters

    • value: DateTime

      The DateTime to compare to the current instance.

    Returns number

    A signed number indicating the relative values of this instance and the value parameter. | Value | Description | | -1 | This instance is earlier than value | | 0 | This instance is same as value | | 1 | This instance is greater than value |

equals

  • equals(value: DateTime | Date): boolean
  • Checks whether a DateTime or Date is equal to current instance.

    Parameters

    • value: DateTime | Date

      The object to compare to this instance.

    Returns boolean

    true if the value parameter equals the value of this instance; otherwise, false.

subtract

  • Subtracts two DateTimes.

    Parameters

    • value: DateTime

      The date and time value to subtract.

    Returns TimeSpan

    A time interval that is equal to the date and time represented by this instance minus the date and time of the value.

subtractTime

  • Subtracts the specified duration from this instance

    Parameters

    • value: TimeSpan

      The time interval to subtract.

    Returns DateTime

    An object that is equal to the date and time represented by this instance minus the time interval represented by

toDate

  • toDate(): Date
  • DateTime as Javascript Date

    Returns Date

    A Javascript Date object that represent this DateTime instance.

toString

  • toString(format?: string): string
  • Turns DateTime into a string with the specified format.

    Patterns Format Description Example
    h 0 12 hour w/o leading zero 3
    hh 00 12 hour with leading zero 03
    hh* 00 12 hour with leading zero 03
    H 0 24 hour w/o leading zero 8
    HH 00 24 hour with leading zero 08
    HH* 00 24 hour with leading zero 08
    m 0 minute w/o leading zero 1
    mm 00 minute with leading zero 01
    mm* 00 minute with leading zero 01
    s 0 second w/o leading zero 5
    ss 00 second with leading zero 05
    ss* 00 second with leading zero 05
    t - first character of AM/PM designator A/P
    tt - AM/PM designator AM/PM
    tt* - AM/PM designator AM/PM
    d 0 day w/o leading zero 1
    dd 00 day with leading zero 01
    ddd - short weekday name (abbreviation) Mon
    dddd - full weekday name Monday
    dddd* - full weekday name Monday
    M 0 month w/o leading zero 2
    MM 00 month with leading zero 02
    MMM - short month name (abbreviation) Feb
    MMMM - full month name February
    MMMM* - full month name February
    y 0 two digit year (year % 100) w/o leading zero 1
    yy 00 two digit year (year % 100) with leading zero 01
    yyyy 0000 full year 2019
    yyyy* 0000 full year 2019
    '...' - quoted string, ignore matching values 'ABC'

    Parameters

    • Default value format: string = "yyyy-MM-ddTHH:mm:ss"

      The format you would like the string in

    Returns string

Static DaysInMonth

  • DaysInMonth(year: number, month: number): number
  • The number of days in the month

    Parameters

    • year: number

      The year of the month

    • month: number

      The month we want to know the days of.

    Returns number

Static IsLeapYear

  • IsLeapYear(year: number): boolean
  • Whether a given year is a leap year

    Parameters

    • year: number

      A year to check

    Returns boolean

Generated using TypeDoc