Lua API
On this page

DateTime

Tip

This is a builtin dotnet type. The documentation and api interface are generated from dotnet source files.

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

Fields:

Date DateTime

read only

Gets the date component of this instance.

Day number

read only

Gets the day of the month represented by this instance.

DayOfWeek DayOfWeek

read only

Gets the day of the week represented by this instance.

DayOfYear number

read only

Gets the day of the year represented by this instance.

Hour number

read only

Gets the hour component of the date represented by this instance.

Kind DateTimeKind

read only

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

MaxValue DateTime

staticread only

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

Microsecond number

read only

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

Millisecond number

read only

Gets the milliseconds component of the date represented by this instance.

Minute number

read only

Gets the minute component of the date represented by this instance.

MinValue DateTime

staticread only

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

Month number

read only

Gets the month component of the date represented by this instance.

Nanosecond number

read only

The nanoseconds component, expressed as a value between 0 and 900 (in increments of 100 nanoseconds).

Now DateTime

staticread only

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

Second number

read only

Gets the seconds component of the date represented by this instance.

Ticks number

read only

Gets the number of ticks that represent the date and time of this instance.

TimeOfDay TimeSpan

read only

Gets the time of day for this instance.

Today DateTime

staticread only

Gets the current date.

UnixEpoch DateTime

staticread only

The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 1970, in the Gregorian calendar. DateTime.UnixEpoch defines the point in time when Unix time is equal to 0.

Year number

read only

Gets the year component of the date represented by this instance.

Constructors:

New(ticks: number) :

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

Parameters:
NameTypeDefaultSummary
ticksnumber

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.

New(date: DateOnly, time: TimeOnly) :

Initializes a new instance of the DateTime structure to the specified DateOnly and TimeOnly. The new instance will have the DateTimeKind.Unspecified kind.

Parameters:
NameTypeDefaultSummary
dateDateOnly

The date part.

timeTimeOnly

The time part.

New(ticks: number, kind: DateTimeKind) :

Initializes a new instance of the DateTime structure to a specified number of ticks and to Coordinated Universal Time (UTC) or local time.

Parameters:
NameTypeDefaultSummary
ticksnumber

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.

kindDateTimeKind

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

New(date: DateOnly, time: TimeOnly, kind: DateTimeKind) :

Initializes a new instance of the DateTime structure to the specified DateOnly and TimeOnly and respecting the specified DateTimeKind.

Parameters:
NameTypeDefaultSummary
dateDateOnly

The date part.

timeTimeOnly

The time part.

kindDateTimeKind

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

New(year: number, month: number, day: number) :

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

Parameters:
NameTypeDefaultSummary
yearnumber

The year (1 through 9999).

monthnumber

The month (1 through 12).

daynumber

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

New(year: number, month: number, day: number, hour: number, minute: number, second: number) :

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

Parameters:
NameTypeDefaultSummary
yearnumber

The year (1 through 9999).

monthnumber

The month (1 through 12).

daynumber

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

hournumber

The hours (0 through 23).

minutenumber

The minutes (0 through 59).

secondnumber

The seconds (0 through 59).

New(year: number, month: number, day: number, hour: number, minute: number, second: number, kind: DateTimeKind) :

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and Coordinated Universal Time (UTC) or local time.

Parameters:
NameTypeDefaultSummary
yearnumber

The year (1 through 9999).

monthnumber

The month (1 through 12).

daynumber

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

hournumber

The hours (0 through 23).

minutenumber

The minutes (0 through 59).

secondnumber

The seconds (0 through 59).

kindDateTimeKind

One of the enumeration values that indicates whether year, month, day, hour, minute and second specify a local time, Coordinated Universal Time (UTC), or neither.

New(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number) :

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

Parameters:
NameTypeDefaultSummary
yearnumber

The year (1 through 9999).

monthnumber

The month (1 through 12).

daynumber

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

hournumber

The hours (0 through 23).

minutenumber

The minutes (0 through 59).

secondnumber

The seconds (0 through 59).

millisecondnumber

The milliseconds (0 through 999).

New(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, kind: DateTimeKind) :

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or local time.

Parameters:
NameTypeDefaultSummary
yearnumber

The year (1 through 9999).

monthnumber

The month (1 through 12).

daynumber

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

hournumber

The hours (0 through 23).

minutenumber

The minutes (0 through 59).

secondnumber

The seconds (0 through 59).

millisecondnumber

The milliseconds (0 through 999).

kindDateTimeKind

One of the enumeration values that indicates whether year, month, day, hour, minute, second, and millisecond specify a local time, Coordinated Universal Time (UTC), or neither.

New(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, microsecond: number) :

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or local time for the specified calendar.

Parameters:
NameTypeDefaultSummary
yearnumber

The year (1 through 9999).

monthnumber

The month (1 through 12).

daynumber

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

hournumber

The hours (0 through 23).

minutenumber

The minutes (0 through 59).

secondnumber

The seconds (0 through 59).

millisecondnumber

The milliseconds (0 through 999).

microsecondnumber

The microseconds (0 through 999).

New(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, microsecond: number, kind: DateTimeKind) :

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or local time for the specified calendar.

Parameters:
NameTypeDefaultSummary
yearnumber

The year (1 through 9999).

monthnumber

The month (1 through 12).

daynumber

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

hournumber

The hours (0 through 23).

minutenumber

The minutes (0 through 59).

secondnumber

The seconds (0 through 59).

millisecondnumber

The milliseconds (0 through 999).

microsecondnumber

The microseconds (0 through 999).

kindDateTimeKind

One of the enumeration values that indicates whether year, month, day, hour, minute, second, and millisecond specify a local time, Coordinated Universal Time (UTC), or neither.

Methods:

Add(value: TimeSpan) : DateTime

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

Parameters:
NameTypeDefaultSummary
valueTimeSpan

A positive or negative time interval.

Returns:DateTime

AddDays(value: number) : DateTime

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

Parameters:
NameTypeDefaultSummary
valuenumber

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

Returns:DateTime

AddHours(value: number) : DateTime

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

Parameters:
NameTypeDefaultSummary
valuenumber

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

Returns:DateTime

AddMicroseconds(value: number) : DateTime

Returns a new DateTime that adds the specified number of microseconds to the value of this instance.

Parameters:
NameTypeDefaultSummary
valuenumber

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

Returns:DateTime

AddMilliseconds(value: number) : DateTime

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

Parameters:
NameTypeDefaultSummary
valuenumber

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

AddMinutes(value) value number

AddMonths(months) months number

AddSeconds(value) value number

AddTicks(value) value number

AddYears(value) value number

Compare(t1,t2) t1 DateTime , t2 DateTime

CompareTo(value) value Object

CompareTo(value) value DateTime

DaysInMonth(year,month) year number , month number

Deconstruct()

Deconstruct()

FromBinary(dateData) dateData number

FromFileTime(fileTime) fileTime number

FromFileTimeUtc(fileTime) fileTime number

FromOADate(d) d number

GetDateTimeFormats()

GetDateTimeFormats(format) format Char

GetTypeCode()

IsDaylightSavingTime()

IsLeapYear(year) year number

Parse(s) s string

SpecifyKind(value,kind) value DateTime , kind DateTimeKind

Subtract(value) value DateTime

Subtract(value) value TimeSpan

ToBinary()

ToFileTime()

ToFileTimeUtc()

ToLocalTime()

ToLongDateString()

ToLongTimeString()

ToOADate()

ToShortDateString()

ToShortTimeString()

ToString()

ToString(format) format string

ToUniversalTime()

TryParse(s) s string