SDateTime
| 函数 | Equals | Returns true if the datetimes are same. |
| 函数 | ComparesTo | 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. |
| 函数 | FormatLocal | Outputs a custom formatted string with the date and time according to local language rules. |
| 函数 | FunctionName | Outputs a custom formatted string with the date and time according to global rules (culture invariant). |
| 函数 | Regional | Outputs a string with the date and time formatted according to specific regional rules. |
| 函数 | FormatRegional | Outputs a custom formatted string with the date and time according to specific regional rules. |
| 函数 | AddYears | Return a new SDateTime that is the current date time + amount years. |
| 函数 | AddMonths | Return a new SDateTime that is the current date time + amount months. |
| 函数 | AddDays | Return a new SDateTime that is the current date time + amount days. |
| 函数 | AddHours | Return a new SDateTime that is the current date time + amount hours. |
| 函数 | AddMinutes | Return a new SDateTime that is the current date time + amount minutes. |
| 函数 | AddSeconds | Return a new SDateTime that is the current date time + amount seconds. |
| 函数 | AddMilliseconds | Return a new SDateTime that is the current date time + amount milliseconds. |
| 函数 | Now | Creates a new SDateTime object equal to the current local time. |
| 函数 | Server | Creates a new SDateTime object equal to the current server time. |
| 函数 | Parse | Creates a new SDateTime object by attempting to parse a string input. |
| 函数 | IsLeapYear | Return true if the specified year is a leap year. |
| 函数 | DaysInMonth | Return the number of days in the given month for the given year. |
| 属性 | Year | Get the independent time unit property of the SDateTime object. |
| 属性 | Month | – |
| 属性 | Day | – |
| 属性 | Hour | – |
| 属性 | Minute | – |
| 属性 | Second | – |
| 属性 | Millisecond | – |
| 属性 | Local | Outputs a string with the date and time formatted according to local language rules. |
| 属性 | Global | Outputs a string with the date and time formatted according to global rules (culture invariant). |
| 属性 | UnixTime | Return this time in Unix time, the number of seconds since Jan 1st, 1970. |
| 属性 | IsDaylightSavingTime | Indicates whether this instance of DateTime is within the daylight saving time range for the current time zone. |
函数
Equals
Returns true if the datetimes are same.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| other | SDateTime | – |
返回值
bool
示例
``` ATargetDateTime = DateTime.Now().AddMinutes(5) AreEqual = ATargetDateTime.Equals(DateTime.Now()) ```
ComparesTo
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.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| other | SDateTime | – |
返回值
int
示例
ATargetDateTime = DateTime.Now().AddMinutes(5)
AreEqual = ATargetDateTime.ComparesTo(DateTime.Now())
FormatLocal
Outputs a custom formatted string with the date and time according to local language rules.
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| format | string | See below for examples |
返回值
string
示例
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
Outputs a custom formatted string with the date and time according to global rules (culture invariant).
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| format | string | – |
返回值
string
示例
GlobalTimeCustomFormat = 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
--]]
Regional
Outputs a string with the date and time formatted according to specific regional rules.
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| region | string | List available here |
返回值
string
示例
stringTimeRegional = DateTime.Now().Regional('en-us')
FormatRegional
Outputs a custom formatted string with the date and time according to specific regional rules.
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| region | string | List available here |
| format | string | See below |
返回值
string
示例
stringTimeFormatRegional = DateTime.Now().FormatRegional('en-us','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
--]]
AddYears
Return a new SDateTime that is the current date time + amount years.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| amount | int | – |
返回值
SDateTime
示例
date5YearsLater = DateTime.Now().AddYears(5)
AddMonths
Return a new SDateTime that is the current date time + amount months.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| amount | int | – |
返回值
SDateTime
示例
date5MonthsLater = DateTime.Now().AddMonths(5)
AddDays
Return a new SDateTime that is the current date time + amount days.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| amount | double | – |
返回值
SDateTime
示例
date5DaysLater = DateTime.Now().AddDays(5)
AddHours
Return a new SDateTime that is the current date time + amount hours.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| amount | double | – |
返回值
SDateTime
示例
date5HoursLater = DateTime.Now().AddHours(5)
AddMinutes
Return a new SDateTime that is the current date time + amount minutes.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| amount | double | – |
返回值
SDateTime
示例
date5MinutesLater = DateTime.Now().AddMinutes(5)
AddSeconds
Return a new SDateTime that is the current date time + amount seconds.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| amount | double | – |
返回值
SDateTime
示例
date5SecondsLater = DateTime.Now().AddSeconds(5)
AddMilliseconds
Return a new SDateTime that is the current date time + amount milliseconds.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| amount | double | – |
返回值
SDateTime
示例
date5MillisecondsLater = DateTime.Now().AddMilliseconds(5)
Now
Creates a new SDateTime object equal to the current local time.
返回值
SDateTime
示例
localDateTime = DateTime.Now()
Server
Creates a new SDateTime object equal to the current server time.
返回值
SDateTime
示例
serverDateTime = DateTime.Server()
Parse
Creates a new SDateTime object by attempting to parse a string input. Returns null/nil if the string cannot be parsed.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| input | string | – |
返回值
SDateTime
示例
parseDateTime = DateTime.Parse('10/3/2022 1:26:02 PM')
IsLeapYear
Return true if the specified year is a leap year.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| year | int | – |
返回值
bool
示例
isLeapYear = DateTime.IsLeapYear(2024)
DaysInMonth
Return the number of days in the given month for the given year.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| year | int | – |
| month | int | – |
返回值
int
示例
isLeapYear = DateTime.DaysInMonth(2022, 8)
属性
Year只读
Get the independent time unit property of the SDateTime object.
示例
currentYear = DateTime.Now().Year
Month只读
示例
currentMonth = DateTime.Now().Month
Day只读
示例
currentDay = DateTime.Now().Day
Hour只读
示例
currentHour = DateTime.Now().Hour
Minute只读
示例
currentMinute = DateTime.Now().Minute
Second只读
示例
currentSecond = DateTime.Now().Second
Millisecond只读
示例
currentMillisecond = DateTime.Now().Millisecond
Local只读
Outputs a string with the date and time formatted according to local language rules.
示例
currentTimeStringLocal = DateTime.Now().Local
Global只读
Outputs a string with the date and time formatted according to global rules (culture invariant).
示例
currentTimeStringGlobal = DateTime.Now().Global
UnixTime只读
Return this time in Unix time, the number of seconds since Jan 1st, 1970.
示例
currentUnixTime = DateTime.Now().UnixTime
IsDaylightSavingTime只读
Indicates whether this instance of DateTime is within the daylight saving time range for the current time zone.
示例
isCurrentTimeDaylightSaving = DateTime.Now().IsDaylightSavingTime



