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

Hierarchy (view full)

Constructors

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

    Parameters

    • ticks: number | Int64

      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 System.DateTime structure to a specified number of ticks and to Coordinated Universal Time (UTC) or local time.

    Parameters

    • ticks: number | Int64

      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.

    • kind: DateTimeKind

      One of the enumeration values that indicates whether ticks specifies a local time, Coordinated Universal Time (UTC), or neither.

    Returns DateTime

Properties

MaxValue: DateTime

Represents the largest possible value of System.DateTime. This field is read-only.

MinValue: DateTime

Represents the smallest possible value of System.DateTime. This field is read-only.

Accessors

  • get Date(): DateTime
  • Gets the date component of this instance.

    Returns DateTime

    A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).

  • get Day(): number
  • Gets the day of the month represented by this instance.

    Returns number

    The day component, expressed as a value between 1 and 31.

  • get DayOfWeek(): DayOfWeek
  • Gets the day of the week represented by this instance.

    Returns DayOfWeek

    An enumerated constant that indicates the day of the week of this System.DateTime value.

  • get DayOfYear(): number
  • Gets the day of the year represented by this instance.

    Returns number

    The day of the year, expressed as a value between 1 and 366.

  • get Hour(): number
  • Gets the hour component of the date represented by this instance.

    Returns number

    The hour component, expressed as a value between 0 and 23.

  • get Kind(): DateTimeKind
  • Gets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither.

    Returns DateTimeKind

    One of the enumeration values that indicates what the current time represents. The default is System.DateTimeKind.Unspecified.

  • get Millisecond(): number
  • Gets the milliseconds component of the date represented by this instance.

    Returns number

    The milliseconds component, expressed as a value between 0 and 999.

  • get Minute(): number
  • Gets the minute component of the date represented by this instance.

    Returns number

    The minute component, expressed as a value between 0 and 59.

  • get Month(): number
  • Gets the month component of the date represented by this instance.

    Returns number

    The month component, expressed as a value between 1 and 12.

  • get Second(): number
  • Gets the seconds component of the date represented by this instance.

    Returns number

    The seconds component, expressed as a value between 0 and 59.

  • get Ticks(): number
  • Gets the number of ticks that represent the date and time of this instance.

    Returns number

    The number of ticks that represent the date and time of this instance. The value is between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.

  • get TimeOfDay(): TimeSpan
  • Gets the time of day for this instance.

    Returns TimeSpan

    A time interval that represents the fraction of the day that has elapsed since midnight.

  • get Year(): number
  • Gets the year component of the date represented by this instance.

    Returns number

    The year, between 1 and 9999.

  • get Now(): DateTime
  • Gets a System.DateTime object that is set to the current date and time on this computer, expressed as the local time.

    Returns DateTime

    An object whose value is the current local date and time.

  • get Today(): DateTime
  • Gets the current date.

    Returns DateTime

    An object that is set to today's date, with the time component set to 00:00:00.

  • get UtcNow(): DateTime
  • Gets a System.DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

    Returns DateTime

    An object whose value is the current UTC date and time.

Methods

  • Returns a new System.DateTime that adds the value of the specified System.TimeSpan to the value of this instance.

    Parameters

    • value: TimeSpan

      A positive or negative time interval.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the time interval represented by value.

  • Returns a new System.DateTime that adds the specified number of days to the value of this instance.

    Parameters

    • value: number | Double

      A number of whole and fractional days. The value parameter can be negative or positive.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of days represented by value.

  • Returns a new System.DateTime that adds the specified number of hours to the value of this instance.

    Parameters

    • value: number | Double

      A number of whole and fractional hours. The value parameter can be negative or positive.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of hours represented by value.

  • Returns a new System.DateTime that adds the specified number of milliseconds to the value of this instance.

    Parameters

    • value: number | Double

      A number of whole and fractional milliseconds. The value parameter can be negative or positive. Note that this value is rounded to the nearest integer.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of milliseconds represented by value.

  • Returns a new System.DateTime that adds the specified number of minutes to the value of this instance.

    Parameters

    • value: number | Double

      A number of whole and fractional minutes. The value parameter can be negative or positive.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of minutes represented by value.

  • Returns a new System.DateTime that adds the specified number of months to the value of this instance.

    Parameters

    • months: number | Int32

      A number of months. The months parameter can be negative or positive.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and months.

  • Returns a new System.DateTime that adds the specified number of seconds to the value of this instance.

    Parameters

    • value: number | Double

      A number of whole and fractional seconds. The value parameter can be negative or positive.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of seconds represented by value.

  • Returns a new System.DateTime that adds the specified number of ticks to the value of this instance.

    Parameters

    • value: number | Int64

      A number of 100-nanosecond ticks. The value parameter can be positive or negative.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the time represented by value.

  • Returns a new System.DateTime that adds the specified number of years to the value of this instance.

    Parameters

    • value: number | Int32

      A number of years. The value parameter can be negative or positive.

    Returns DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of years represented by value.

  • Casts this object to the specified type. Throws error on failure.

    Type Parameters

    • T1

      The target type of the cast.

    • T2

      The type of the object to cast.

    Parameters

    Returns T1

  • Determines whether the specified object is equal to the current object.

    Parameters

    • obj: any

      The object to compare with the current object.

    Returns boolean

    true if the specified object is equal to the current object; otherwise, false.

  • Serves as the default hash function.

    Returns number

    A hash code for the current object.

  • Subtracts the specified date and time from this instance.

    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 represented by value.

  • 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 value.

  • Converts the value of the current System.DateTime object to its equivalent long date string representation.

    Returns string

    A string that contains the long date string representation of the current System.DateTime object.

  • Converts the value of the current System.DateTime object to its equivalent long time string representation.

    Returns string

    A string that contains the long time string representation of the current System.DateTime object.

  • Converts the value of the current System.DateTime object to its equivalent short date string representation.

    Returns string

    A string that contains the short date string representation of the current System.DateTime object.

  • Converts the value of the current System.DateTime object to its equivalent short time string representation.

    Returns string

    A string that contains the short time string representation of the current System.DateTime object.

  • Returns a string that represents the current object.

    Returns string

    A string that represents the current object.

  • Casts this object to the specified type. Returns null on failure.

    Type Parameters

    • T1

      The target type of the cast.

    • T2

      The type of the object to cast.

    Parameters

    Returns null | T1

  • Returns the number of days in the specified month and year.

    Parameters

    • year: number | Int32

      The year.

    • month: number | Int32

      The month (a number ranging from 1 to 12).

    Returns number

    The number of days in month for the specified year. For example, if month equals 2 for February, the return value is 28 or 29 depending upon whether year is a leap year.

  • Determines whether the specified object instances are considered equal.

    Parameters

    • objA: any

      The first object to compare.

    • objB: any

      The second object to compare.

    Returns boolean

    true if the objects are considered equal; otherwise, false. If both objA and objB are null, the method returns true.

  • Converts the string representation of a date and time to its System.DateTime equivalent by using the conventions of the current thread culture.

    Parameters

    • s: string | String

      A string that contains a date and time to convert. See The string to parse for more information.

    Returns DateTime

    An object that is equivalent to the date and time contained in s.

  • Creates a new System.DateTime object that has the same number of ticks as the specified System.DateTime, but is designated as either local time, Coordinated Universal Time (UTC), or neither, as indicated by the specified System.DateTimeKind value.

    Parameters

    • value: DateTime

      A date and time.

    • kind: DateTimeKind

      One of the enumeration values that indicates whether the new object represents local time, UTC, or neither.

    Returns DateTime

    A new object that has the same number of ticks as the object represented by the value parameter and the System.DateTimeKind value specified by the kind parameter.

  • Converts the specified string representation of a date and time to its System.DateTime equivalent and returns a value that indicates whether the conversion succeeded.

    Parameters

    • s: string | String

      A string containing a date and time to convert.

    • result: OutParam<DateTime>

      When this method returns, contains the System.DateTime value equivalent to the date and time contained in s, if the conversion succeeded, or System.DateTime.MinValue if the conversion failed. The conversion fails if the s parameter is null, is an empty string (""), or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.

    Returns boolean

    true if the s parameter was converted successfully; otherwise, false.