struct · System

DateTime

public struct System.DateTime : System.IHashable<System.DateTime>, System.IComparable<System.DateTime>

A moment on the calendar, from 0001-01-01 to 9999-12-31, to 100 ns, and whose clock it reads (Kind). date + span, date - span, a - b (a TimeSpan) and the comparisons work on it; as text it is MM/dd/yyyy HH:mm:ss, and ToString("o") gives the round-trip form.

Kind
struct
Namespace
System
Assembly
System.Core
Access
public
Source file
Time.ant

Inheritance

Interfaces
IHashable<TSelf> IComparable<TSelf>

Constructors

constructor DateTime(ticks: i64)
#

Ticks since 0001-01-01 00:00:00.

constructor DateTime(ticks: i64, kind: System.DateTimeKind)
#
constructor DateTime(year: i32, month: i32, day: i32)
#
constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32)
#
constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, kind: System.DateTimeKind)
#
constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, millisecond: i32)
#
constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, millisecond: i32, kind: System.DateTimeKind)
#

Properties

static property MinValue: System.DateTime
#

static read-only

static property MaxValue: System.DateTime
#

static read-only

static property UnixEpoch: System.DateTime
#

static read-only

1970-01-01 00:00:00 UTC.

static property UtcNow: System.DateTime
#

static read-only

Now: in UTC, in the local time zone, and today's date (local, at midnight).

static property Now: System.DateTime
#

static read-only

static property Today: System.DateTime
#

static read-only

property Ticks: i64
#

read-only

property Kind: System.DateTimeKind
#

read-only

property Year: i32
#

read-only

property Month: i32
#

read-only

property Day: i32
#

read-only

property Hour: i32
#

read-only

property Minute: i32
#

read-only

property Second: i32
#

read-only

property Millisecond: i32
#

read-only

property Microsecond: i32
#

read-only

property Nanosecond: i32
#

read-only

read-only

property DayOfYear: i32
#

read-only

1 for January 1st.

property Date: System.DateTime
#

read-only

The date at midnight (same kind), and the time since midnight.

property TimeOfDay: System.TimeSpan
#

read-only

Methods

static method IsLeapYear(year: i32) -> bool
#

static

static method DaysInMonth(year: i32, month: i32) -> i32
#

static

static method SpecifyKind(value: System.DateTime, kind: System.DateTimeKind) -> System.DateTime
#

static

The same moment with another kind (the clock reading is not changed).

method Add(span: System.TimeSpan) -> System.DateTime
#
method AddTicks(value: i64) -> System.DateTime
#
method AddDays(value: f64) -> System.DateTime
#
method AddHours(value: f64) -> System.DateTime
#
method AddMinutes(value: f64) -> System.DateTime
#
method AddSeconds(value: f64) -> System.DateTime
#
method AddMilliseconds(value: f64) -> System.DateTime
#
method AddMicroseconds(value: f64) -> System.DateTime
#
method AddMonths(months: i32) -> System.DateTime
#

months months later: the same day, or the month's last day when it is shorter.

method AddYears(years: i32) -> System.DateTime
#
method Subtract(other: System.DateTime) -> System.TimeSpan
#

The time from other to this moment, and this moment span earlier.

method Subtract(span: System.TimeSpan) -> System.DateTime
#
method Equals(other: System.DateTime) -> bool
#

The same moment (the kind is not compared).

method Hash() -> u64
#
method CompareTo(other: System.DateTime) -> i32
#
static method Compare(a: System.DateTime, b: System.DateTime) -> i32
#

static

method ToUniversalTime() -> System.DateTime
#

The moment on UTC's clock and on the local time zone's (Unspecified counts as the other one).

method ToLocalTime() -> System.DateTime
#
method ToUnixTimeSeconds() -> i64
#

Seconds and milliseconds since 1970-01-01 UTC (Unspecified counts as UTC), and the UTC moment of a count of them.

method ToUnixTimeMilliseconds() -> i64
#
static method FromUnixTimeSeconds(seconds: i64) -> System.DateTime
#

static

static method FromUnixTimeMilliseconds(milliseconds: i64) -> System.DateTime
#

static

method ToString() -> System.String<u8>
#

MM/dd/yyyy HH:mm:ss.

method ToString(format: System.String<u8>) -> System.String<u8>
#

As text by a format: a standard one (d, D, f, F, g, G, M, o, R, s, t, T, u, U, Y) or a custom one of yyyy, yy, MMMM, MMM, MM, M, dddd, ddd, dd, d, HH, H, hh, h, mm, m, ss, s, f…, F…, tt, t, K, zzz, zz, z, 'text', "text" and \x.

static method Parse(text: System.String<u8>) -> System.DateTime
#

static

The moment text writes: ISO 8601 (2024-05-01, 2024-05-01T13:45:30.5Z, …+02:00), the invariant culture's 05/01/2024 1:45 PM, Wed, 01 May 2024 13:45:30 GMT, 1 May 2024, May 1, 2024, or a time alone (today); a FormatError when it writes none.

static method Parse(text: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime
#

static

static method ParseExact(text: System.String<u8>, format: System.String<u8>) -> System.DateTime
#

static

The moment text writes in exactly format (a standard or custom format, as ToString takes).

static method ParseExact(text: System.String<u8>, format: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime
#

static

static method TryParse(text: System.String<u8>) -> System.DateTime?
#

static

The moment, or null when text writes none.

static method TryParse(text: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime?
#

static

static method TryParseExact(text: System.String<u8>, format: System.String<u8>) -> System.DateTime?
#

static

static method TryParseExact(text: System.String<u8>, format: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime?
#

static

method ToBinary() -> i64
#

The bits (ticks and kind), and a DateTime from them.

static method FromBinary(bits: i64) -> System.DateTime
#

static

Operators and conversions

static operator $op_Add(d: System.DateTime, span: System.TimeSpan) -> System.DateTime
#

static

static operator $op_Subtract(d: System.DateTime, span: System.TimeSpan) -> System.DateTime
#

static

static operator $op_Subtract(a: System.DateTime, b: System.DateTime) -> System.TimeSpan
#

static

static operator $op_Equal(a: System.DateTime, b: System.DateTime) -> bool
#

static

static operator $op_NotEqual(a: System.DateTime, b: System.DateTime) -> bool
#

static

static operator $op_Less(a: System.DateTime, b: System.DateTime) -> bool
#

static

static operator $op_LessEqual(a: System.DateTime, b: System.DateTime) -> bool
#

static

static operator $op_Greater(a: System.DateTime, b: System.DateTime) -> bool
#

static

static operator $op_GreaterEqual(a: System.DateTime, b: System.DateTime) -> bool
#

static

Private and internal members (7)

field data: u64
#

private

static method OutOfRange(which: i32) -> void
#

private static

Throws an ArgumentOutOfRangeError: the message is made here, so the fast paths that may throw allocate nothing.

static method Of(data: u64) -> System.DateTime
#

private static

A DateTime from its bits (ticks already checked).

static method DateTicks(year: i32, month: i32, day: i32) -> i64
#

private static

The ticks of a date (checked), as .NET's DateToTicks.

static method TimeTicks(hour: i32, minute: i32, second: i32) -> i64
#

private static

method Moved(value: i64) -> System.DateTime
#

private

This moment value ticks later (an ArgumentOutOfRangeError past the calendar's ends).

method AddUnits(value: f64, most: i64, scale: i64) -> System.DateTime
#

private

value units of scale ticks later: whole units exactly, the fraction rounded toward zero.

Source

DateTime as Larva HIR, decompiled from its Larva HIR.

System.DateTime.hir
// A moment on the calendar, from 0001-01-01 to 9999-12-31, to 100 ns, and whose clock it reads (Kind).
// `date + span`, `date - span`, `a - b` (a TimeSpan) and the comparisons work on it; as text it is
// `MM/dd/yyyy HH:mm:ss`, and ToString("o") gives the round-trip form.
public struct System.DateTime : System.IHashable<System.DateTime>, System.IComparable<System.DateTime>
{
    field data: u64
    // Throws an ArgumentOutOfRangeError: the message is made here, so the fast paths that may throw allocate nothing.
    static method OutOfRange(which: i32) -> void
    // A DateTime from its bits (ticks already checked).
    static method Of(data: u64) -> System.DateTime
    // The ticks of a date (checked), as .NET's DateToTicks.
    static method DateTicks(year: i32, month: i32, day: i32) -> i64
    static method TimeTicks(hour: i32, minute: i32, second: i32) -> i64
    // This moment `value` ticks later (an ArgumentOutOfRangeError past the calendar's ends).
    method Moved(value: i64) -> System.DateTime
    // `value` units of `scale` ticks later: whole units exactly, the fraction rounded toward zero.
    method AddUnits(value: f64, most: i64, scale: i64) -> System.DateTime
    // Ticks since 0001-01-01 00:00:00.
    constructor DateTime(ticks: i64)
    constructor DateTime(ticks: i64, kind: System.DateTimeKind)
    constructor DateTime(year: i32, month: i32, day: i32)
    constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32)
    constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, kind: System.DateTimeKind)
    constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, millisecond: i32)
    constructor DateTime(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, millisecond: i32, kind: System.DateTimeKind)
    static method IsLeapYear(year: i32) -> bool
    static method DaysInMonth(year: i32, month: i32) -> i32
    // The same moment with another kind (the clock reading is not changed).
    static method SpecifyKind(value: System.DateTime, kind: System.DateTimeKind) -> System.DateTime
    method Add(span: System.TimeSpan) -> System.DateTime
    method AddTicks(value: i64) -> System.DateTime
    method AddDays(value: f64) -> System.DateTime
    method AddHours(value: f64) -> System.DateTime
    method AddMinutes(value: f64) -> System.DateTime
    method AddSeconds(value: f64) -> System.DateTime
    method AddMilliseconds(value: f64) -> System.DateTime
    method AddMicroseconds(value: f64) -> System.DateTime
    // `months` months later: the same day, or the month's last day when it is shorter.
    method AddMonths(months: i32) -> System.DateTime
    method AddYears(years: i32) -> System.DateTime
    // The time from `other` to this moment, and this moment `span` earlier.
    method Subtract(other: System.DateTime) -> System.TimeSpan
    method Subtract(span: System.TimeSpan) -> System.DateTime
    static operator $op_Add(d: System.DateTime, span: System.TimeSpan) -> System.DateTime
    static operator $op_Subtract(d: System.DateTime, span: System.TimeSpan) -> System.DateTime
    static operator $op_Subtract(a: System.DateTime, b: System.DateTime) -> System.TimeSpan
    static operator $op_Equal(a: System.DateTime, b: System.DateTime) -> bool
    static operator $op_NotEqual(a: System.DateTime, b: System.DateTime) -> bool
    static operator $op_Less(a: System.DateTime, b: System.DateTime) -> bool
    static operator $op_LessEqual(a: System.DateTime, b: System.DateTime) -> bool
    static operator $op_Greater(a: System.DateTime, b: System.DateTime) -> bool
    static operator $op_GreaterEqual(a: System.DateTime, b: System.DateTime) -> bool
    // The same moment (the kind is not compared).
    method Equals(other: System.DateTime) -> bool
    method Hash() -> u64
    method CompareTo(other: System.DateTime) -> i32
    static method Compare(a: System.DateTime, b: System.DateTime) -> i32
    // The moment on UTC's clock and on the local time zone's (Unspecified counts as the other one).
    method ToUniversalTime() -> System.DateTime
    method ToLocalTime() -> System.DateTime
    // Seconds and milliseconds since 1970-01-01 UTC (Unspecified counts as UTC), and the UTC moment of a count of
    // them.
    method ToUnixTimeSeconds() -> i64
    method ToUnixTimeMilliseconds() -> i64
    static method FromUnixTimeSeconds(seconds: i64) -> System.DateTime
    static method FromUnixTimeMilliseconds(milliseconds: i64) -> System.DateTime
    // `MM/dd/yyyy HH:mm:ss`.
    method ToString() -> System.String<u8>
    // As text by a format: a standard one (d, D, f, F, g, G, M, o, R, s, t, T, u, U, Y) or a custom one of
    // yyyy, yy, MMMM, MMM, MM, M, dddd, ddd, dd, d, HH, H, hh, h, mm, m, ss, s, f…, F…, tt, t, K, zzz, zz, z,
    // 'text', "text" and \x.
    method ToString(format: System.String<u8>) -> System.String<u8>
    // The moment `text` writes: ISO 8601 (`2024-05-01`, `2024-05-01T13:45:30.5Z`, `…+02:00`), the invariant
    // culture's `05/01/2024 1:45 PM`, `Wed, 01 May 2024 13:45:30 GMT`, `1 May 2024`, `May 1, 2024`, or a time
    // alone (today); a FormatError when it writes none.
    static method Parse(text: System.String<u8>) -> System.DateTime
    static method Parse(text: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime
    // The moment `text` writes in exactly `format` (a standard or custom format, as ToString takes).
    static method ParseExact(text: System.String<u8>, format: System.String<u8>) -> System.DateTime
    static method ParseExact(text: System.String<u8>, format: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime
    // The moment, or null when `text` writes none.
    static method TryParse(text: System.String<u8>) -> System.DateTime?
    static method TryParse(text: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime?
    static method TryParseExact(text: System.String<u8>, format: System.String<u8>) -> System.DateTime?
    static method TryParseExact(text: System.String<u8>, format: System.String<u8>, styles: System.DateTimeStyles) -> System.DateTime?
    // The bits (ticks and kind), and a DateTime from them.
    method ToBinary() -> i64
    static method FromBinary(bits: i64) -> System.DateTime
    static property MinValue: System.DateTime
    static property MaxValue: System.DateTime
    // 1970-01-01 00:00:00 UTC.
    static property UnixEpoch: System.DateTime
    // Now: in UTC, in the local time zone, and today's date (local, at midnight).
    static property UtcNow: System.DateTime
    static property Now: System.DateTime
    static property Today: System.DateTime
    property Ticks: i64
    property Kind: System.DateTimeKind
    property Year: i32
    property Month: i32
    property Day: i32
    property Hour: i32
    property Minute: i32
    property Second: i32
    property Millisecond: i32
    property Microsecond: i32
    property Nanosecond: i32
    property DayOfWeek: System.DayOfWeek
    // 1 for January 1st.
    property DayOfYear: i32
    // The date at midnight (same kind), and the time since midnight.
    property Date: System.DateTime
    property TimeOfDay: System.TimeSpan
}
Esc