Breakroom is now Sinewave Campus. Book a meeting

SDateTime

客户端类型
在此类中Equals
  1. 函数
  2. Equals
  3. ComparesTo
  4. FormatLocal
  5. FunctionName
  6. Regional
  7. FormatRegional
  8. AddYears
  9. AddMonths
  10. AddDays
  11. AddHours
  12. AddMinutes
  13. AddSeconds
  14. AddMilliseconds
  15. Now
  16. Server
  17. Parse
  18. IsLeapYear
  19. DaysInMonth
  20. 属性
  21. Year
  22. Month
  23. Day
  24. Hour
  25. Minute
  26. Second
  27. Millisecond
  28. Local
  29. Global
  30. UnixTime
  31. IsDaylightSavingTime
成员 29
函数EqualsReturns true if the datetimes are same.
函数ComparesToCompares two datetimes and returns an integer. 0 == identical. greater than 0 == This datetime is greater than other. less than 0 == This datetime is less than other.
函数FormatLocalOutputs a custom formatted string with the date and time according to local language rules.
函数FunctionNameOutputs a custom formatted string with the date and time according to global rules (culture invariant).
函数RegionalOutputs a string with the date and time formatted according to specific regional rules.
函数FormatRegionalOutputs a custom formatted string with the date and time according to specific regional rules.
函数AddYearsReturn a new SDateTime that is the current date time + amount years.
函数AddMonthsReturn a new SDateTime that is the current date time + amount months.
函数AddDaysReturn a new SDateTime that is the current date time + amount days.
函数AddHoursReturn a new SDateTime that is the current date time + amount hours.
函数AddMinutesReturn a new SDateTime that is the current date time + amount minutes.
函数AddSecondsReturn a new SDateTime that is the current date time + amount seconds.
函数AddMillisecondsReturn a new SDateTime that is the current date time + amount milliseconds.
函数NowCreates a new SDateTime object equal to the current local time.
函数ServerCreates a new SDateTime object equal to the current server time.
函数ParseCreates a new SDateTime object by attempting to parse a string input.
函数IsLeapYearReturn true if the specified year is a leap year.
函数DaysInMonthReturn the number of days in the given month for the given year.
属性YearGet the independent time unit property of the SDateTime object.
属性Month–
属性Day–
属性Hour–
属性Minute–
属性Second–
属性Millisecond–
属性LocalOutputs a string with the date and time formatted according to local language rules.
属性GlobalOutputs a string with the date and time formatted according to global rules (culture invariant).
属性UnixTimeReturn this time in Unix time, the number of seconds since Jan 1st, 1970.
属性IsDaylightSavingTimeIndicates whether this instance of DateTime is within the daylight saving time range for the current time zone.

函数​

Equals​

bool Equals(SDateTime other)

Returns true if the datetimes are same.

参数

名称类型默认值
otherSDateTime–

返回值

bool

示例

``` ATargetDateTime = DateTime.Now().AddMinutes(5) AreEqual = ATargetDateTime.Equals(DateTime.Now()) ```

ComparesTo​

int ComparesTo(SDateTime other)

Compares two datetimes and returns an integer. 0 == identical. greater than 0 == This datetime is greater than other. less than 0 == This datetime is less than other.

参数

名称类型默认值
otherSDateTime–

返回值

int

示例

Lua
ATargetDateTime = DateTime.Now().AddMinutes(5)
AreEqual = ATargetDateTime.ComparesTo(DateTime.Now())

FormatLocal​

string FormatLocal(string format)

Outputs a custom formatted string with the date and time according to local language rules.

参数

参数类型说明
formatstringSee below for examples

返回值

string

示例

Lua
localTimeCustomFormat = DateTime.Now().FormatLocal("dddd, MMMM dd, yyyy h:mm:ss tt")

``` --Example format strings

--[[ format = "dddd, MMMM dd, yyyy h:mm:ss tt" Result: Monday, May 28, 2012 11:35:00 AM

format = "Ldddd, MMMM dd, yyyy" Result: Monday, May 28, 2012

format = "h:mm:ss tt" Result: 11:35:00 AM

format = "MMMM dd" Result: May 28

format = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT" Result: Mon, 28 May 2012 11:35:00 GMT

format = "M/d/yyyy" Result: 5/28/2012

format = "h:mm tt" Result: 11:35 AM

format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss" Result: 2012-05-28T11:35:00

format = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'" Result: 2012-05-28 11:35:00Z

format = "MMMM, yyyy" Result: May, 2012 --]] ```

FunctionName​

string FormatGlobal(string format)

Outputs a custom formatted string with the date and time according to global rules (culture invariant).

参数

名称类型默认值
formatstring–

返回值

string

示例

Lua
GlobalTimeCustomFormat = DateTime.Now().FormatLocal("dddd, MMMM dd, yyyy h:mm:ss tt")
Lua
--Example format strings

--[[
format = "dddd, MMMM dd, yyyy h:mm:ss tt"
Result: Monday, May 28, 2012 11:35:00 AM

format = "Ldddd, MMMM dd, yyyy"
Result: Monday, May 28, 2012

format = "h:mm:ss tt"
Result: 11:35:00 AM

format = "MMMM dd"
Result: May 28

format = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT"
Result: Mon, 28 May 2012 11:35:00 GMT

format = "M/d/yyyy"
Result: 5/28/2012

format = "h:mm tt"
Result: 11:35 AM

format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"
Result: 2012-05-28T11:35:00

format = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"
Result: 2012-05-28 11:35:00Z

format = "MMMM, yyyy"
Result: May, 2012
--]]

Regional​

string Regional(string region)

Outputs a string with the date and time formatted according to specific regional rules.

参数

参数类型说明
regionstringList available here

返回值

string

示例

Lua
stringTimeRegional = DateTime.Now().Regional('en-us')

FormatRegional​

string FormatRegional(string region, string format)

Outputs a custom formatted string with the date and time according to specific regional rules.

参数

参数类型说明
regionstringList available here
formatstringSee below

返回值

string

示例

Lua
stringTimeFormatRegional = DateTime.Now().FormatRegional('en-us','dddd, MMMM dd, yyyy h:mm:ss tt')
Lua
--Example format strings

--[[
format = "dddd, MMMM dd, yyyy h:mm:ss tt"
Result: Monday, May 28, 2012 11:35:00 AM

format = "Ldddd, MMMM dd, yyyy"
Result: Monday, May 28, 2012

format = "h:mm:ss tt"
Result: 11:35:00 AM

format = "MMMM dd"
Result: May 28

format = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT"
Result: Mon, 28 May 2012 11:35:00 GMT

format = "M/d/yyyy"
Result: 5/28/2012

format = "h:mm tt"
Result: 11:35 AM

format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"
Result: 2012-05-28T11:35:00

format = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"
Result: 2012-05-28 11:35:00Z

format = "MMMM, yyyy"
Result: May, 2012
--]]

AddYears​

SDateTime AddYears(int amount)

Return a new SDateTime that is the current date time + amount years.

参数

名称类型默认值
amountint–

返回值

SDateTime

示例

Lua
date5YearsLater = DateTime.Now().AddYears(5)

AddMonths​

SDateTime AddMonths(int amount)

Return a new SDateTime that is the current date time + amount months.

参数

名称类型默认值
amountint–

返回值

SDateTime

示例

Lua
date5MonthsLater = DateTime.Now().AddMonths(5)

AddDays​

SDateTime AddDays(double amount)

Return a new SDateTime that is the current date time + amount days.

参数

名称类型默认值
amountdouble–

返回值

SDateTime

示例

Lua
date5DaysLater = DateTime.Now().AddDays(5)

AddHours​

SDateTime AddHours(double amount)

Return a new SDateTime that is the current date time + amount hours.

参数

名称类型默认值
amountdouble–

返回值

SDateTime

示例

Lua
date5HoursLater = DateTime.Now().AddHours(5)

AddMinutes​

SDateTime AddMinutes(double amount)

Return a new SDateTime that is the current date time + amount minutes.

参数

名称类型默认值
amountdouble–

返回值

SDateTime

示例

Lua
date5MinutesLater = DateTime.Now().AddMinutes(5)

AddSeconds​

SDateTime AddSeconds(double amount)

Return a new SDateTime that is the current date time + amount seconds.

参数

名称类型默认值
amountdouble–

返回值

SDateTime

示例

Lua
date5SecondsLater = DateTime.Now().AddSeconds(5)

AddMilliseconds​

SDateTime AddMilliseconds(double amount)

Return a new SDateTime that is the current date time + amount milliseconds.

参数

名称类型默认值
amountdouble–

返回值

SDateTime

示例

Lua
date5MillisecondsLater = DateTime.Now().AddMilliseconds(5)

Now​

static SDateTime Now()

Creates a new SDateTime object equal to the current local time.

返回值

SDateTime

示例

Lua
localDateTime = DateTime.Now()

Server​

static SDateTime Server()

Creates a new SDateTime object equal to the current server time.

返回值

SDateTime

示例

Lua
serverDateTime = DateTime.Server()

Parse​

static SDateTime Parse(string input)

Creates a new SDateTime object by attempting to parse a string input. Returns null/nil if the string cannot be parsed.

参数

名称类型默认值
inputstring–

返回值

SDateTime

示例

Lua
parseDateTime = DateTime.Parse('10/3/2022 1:26:02 PM')

IsLeapYear​

static bool IsLeapYear(int year)

Return true if the specified year is a leap year.

参数

名称类型默认值
yearint–

返回值

bool

示例

Lua
isLeapYear = DateTime.IsLeapYear(2024)

DaysInMonth​

static int DaysInMonth(int year, int month)

Return the number of days in the given month for the given year.

参数

名称类型默认值
yearint–
monthint–

返回值

int

示例

Lua
isLeapYear = DateTime.DaysInMonth(2022, 8)

属性​

Year只读​

int Year {get; }

Get the independent time unit property of the SDateTime object.

示例

Lua
currentYear = DateTime.Now().Year

Month只读​

int Month {get; }

示例

Lua
currentMonth = DateTime.Now().Month

Day只读​

int Day {get; }

示例

Lua
currentDay = DateTime.Now().Day

Hour只读​

int Hour {get; }

示例

Lua
currentHour = DateTime.Now().Hour

Minute只读​

int Minute {get; }

示例

Lua
currentMinute = DateTime.Now().Minute

Second只读​

int Second {get; }

示例

Lua
currentSecond = DateTime.Now().Second

Millisecond只读​

int Millisecond {get; }

示例

Lua
currentMillisecond = DateTime.Now().Millisecond

Local只读​

string Local {get; }

Outputs a string with the date and time formatted according to local language rules.

示例

Lua
currentTimeStringLocal = DateTime.Now().Local

Global只读​

string Global {get; }

Outputs a string with the date and time formatted according to global rules (culture invariant).

示例

Lua
currentTimeStringGlobal = DateTime.Now().Global

UnixTime只读​

int UnixTime {get; }

Return this time in Unix time, the number of seconds since Jan 1st, 1970.

示例

Lua
currentUnixTime = DateTime.Now().UnixTime

IsDaylightSavingTime只读​

bool IsDaylightSavingTime {get; }

Indicates whether this instance of DateTime is within the daylight saving time range for the current time zone.

示例

Lua
isCurrentTimeDaylightSaving = DateTime.Now().IsDaylightSavingTime