# SDateTime

**Membres** 29

|           |                                               |                                                                                                                                                                        |
| --------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Fonction  | [Equals](#equals)                             | Returns true if the datetimes are same.                                                                                                                                |
| Fonction  | [ComparesTo](#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. |
| Fonction  | [FormatLocal](#formatlocal)                   | Outputs a custom formatted string with the date and time according to local language rules.                                                                            |
| Fonction  | [FunctionName](#functionname)                 | Outputs a custom formatted string with the date and time according to global rules (culture invariant).                                                                |
| Fonction  | [Regional](#regional)                         | Outputs a string with the date and time formatted according to specific regional rules.                                                                                |
| Fonction  | [FormatRegional](#formatregional)             | Outputs a custom formatted string with the date and time according to specific regional rules.                                                                         |
| Fonction  | [AddYears](#addyears)                         | Return a new SDateTime that is the current date time + amount years.                                                                                                   |
| Fonction  | [AddMonths](#addmonths)                       | Return a new SDateTime that is the current date time + amount months.                                                                                                  |
| Fonction  | [AddDays](#adddays)                           | Return a new SDateTime that is the current date time + amount days.                                                                                                    |
| Fonction  | [AddHours](#addhours)                         | Return a new SDateTime that is the current date time + amount hours.                                                                                                   |
| Fonction  | [AddMinutes](#addminutes)                     | Return a new SDateTime that is the current date time + amount minutes.                                                                                                 |
| Fonction  | [AddSeconds](#addseconds)                     | Return a new SDateTime that is the current date time + amount seconds.                                                                                                 |
| Fonction  | [AddMilliseconds](#addmilliseconds)           | Return a new SDateTime that is the current date time + amount milliseconds.                                                                                            |
| Fonction  | [Now](#now)                                   | Creates a new SDateTime object equal to the current local time.                                                                                                        |
| Fonction  | [Server](#server)                             | Creates a new SDateTime object equal to the current server time.                                                                                                       |
| Fonction  | [Parse](#parse)                               | Creates a new SDateTime object by attempting to parse a string input.                                                                                                  |
| Fonction  | [IsLeapYear](#isleapyear)                     | Return true if the specified year is a leap year.                                                                                                                      |
| Fonction  | [DaysInMonth](#daysinmonth)                   | Return the number of days in the given month for the given year.                                                                                                       |
| Propriété | [Year](#year)                                 | Get the independent time unit property of the SDateTime object.                                                                                                        |
| Propriété | [Month](#month)                               | –                                                                                                                                                                      |
| Propriété | [Day](#day)                                   | –                                                                                                                                                                      |
| Propriété | [Hour](#hour)                                 | –                                                                                                                                                                      |
| Propriété | [Minute](#minute)                             | –                                                                                                                                                                      |
| Propriété | [Second](#second)                             | –                                                                                                                                                                      |
| Propriété | [Millisecond](#millisecond)                   | –                                                                                                                                                                      |
| Propriété | [Local](#local)                               | Outputs a string with the date and time formatted according to local language rules.                                                                                   |
| Propriété | [Global](#global)                             | Outputs a string with the date and time formatted according to global rules (culture invariant).                                                                       |
| Propriété | [UnixTime](#unixtime)                         | Return this time in Unix time, the number of seconds since Jan 1st, 1970.                                                                                              |
| Propriété | [IsDaylightSavingTime](#isdaylightsavingtime) | Indicates whether this instance of DateTime is within the daylight saving time range for the current time zone.                                                        |

## Fonctions

### Equals

bool Equals(SDateTime other)

Returns true if the datetimes are same.

Paramètres

| Nom   | Type      | Valeur par défaut |
| ----- | --------- | ----------------- |
| other | SDateTime | –                 |

Valeurs de retour

`bool`

Exemple

\`\`\` 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.

Paramètres

| Nom   | Type      | Valeur par défaut |
| ----- | --------- | ----------------- |
| other | SDateTime | –                 |

Valeurs de retour

`int`

Exemple

**Lua**

```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.

Paramètres

| Paramètre | Type   | Description            |
| --------- | ------ | ---------------------- |
| format    | string | See below for examples |

Valeurs de retour

`string`

Exemple

**Lua**

```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).

Paramètres

| Nom    | Type   | Valeur par défaut |
| ------ | ------ | ----------------- |
| format | string | –                 |

Valeurs de retour

`string`

Exemple

**Lua**

```lua
GlobalTimeCustomFormat = DateTime.Now().FormatLocal("dddd, MMMM dd, yyyy h:mm:ss tt")

```

**Lua**

```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.

Paramètres

| Paramètre | Type   | Description                                                                                                                       |
| --------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| region    | string | [List available here](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c) |

Valeurs de retour

`string`

Exemple

**Lua**

```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.

Paramètres

| Paramètre | Type   | Description                                                                                                                       |
| --------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| region    | string | [List available here](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c) |
| format    | string | See below                                                                                                                         |

Valeurs de retour

`string`

Exemple

**Lua**

```lua
stringTimeFormatRegional = DateTime.Now().FormatRegional('en-us','dddd, MMMM dd, yyyy h:mm:ss tt')

```

**Lua**

```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.

Paramètres

| Nom    | Type | Valeur par défaut |
| ------ | ---- | ----------------- |
| amount | int  | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
date5YearsLater = DateTime.Now().AddYears(5)

```

### AddMonths

SDateTime AddMonths(int amount)

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

Paramètres

| Nom    | Type | Valeur par défaut |
| ------ | ---- | ----------------- |
| amount | int  | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
date5MonthsLater = DateTime.Now().AddMonths(5)

```

### AddDays

SDateTime AddDays(double amount)

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

Paramètres

| Nom    | Type   | Valeur par défaut |
| ------ | ------ | ----------------- |
| amount | double | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
date5DaysLater = DateTime.Now().AddDays(5)

```

### AddHours

SDateTime AddHours(double amount)

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

Paramètres

| Nom    | Type   | Valeur par défaut |
| ------ | ------ | ----------------- |
| amount | double | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
date5HoursLater = DateTime.Now().AddHours(5)

```

### AddMinutes

SDateTime AddMinutes(double amount)

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

Paramètres

| Nom    | Type   | Valeur par défaut |
| ------ | ------ | ----------------- |
| amount | double | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
date5MinutesLater = DateTime.Now().AddMinutes(5)

```

### AddSeconds

SDateTime AddSeconds(double amount)

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

Paramètres

| Nom    | Type   | Valeur par défaut |
| ------ | ------ | ----------------- |
| amount | double | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
date5SecondsLater = DateTime.Now().AddSeconds(5)

```

### AddMilliseconds

SDateTime AddMilliseconds(double amount)

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

Paramètres

| Nom    | Type   | Valeur par défaut |
| ------ | ------ | ----------------- |
| amount | double | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
date5MillisecondsLater = DateTime.Now().AddMilliseconds(5)

```

### Now

static SDateTime Now()

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

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```lua
localDateTime = DateTime.Now()

```

### Server

static SDateTime Server()

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

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```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.

Paramètres

| Nom   | Type   | Valeur par défaut |
| ----- | ------ | ----------------- |
| input | string | –                 |

Valeurs de retour

`SDateTime`

Exemple

**Lua**

```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.

Paramètres

| Nom  | Type | Valeur par défaut |
| ---- | ---- | ----------------- |
| year | int  | –                 |

Valeurs de retour

`bool`

Exemple

**Lua**

```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.

Paramètres

| Nom   | Type | Valeur par défaut |
| ----- | ---- | ----------------- |
| year  | int  | –                 |
| month | int  | –                 |

Valeurs de retour

`int`

Exemple

**Lua**

```lua
isLeapYear = DateTime.DaysInMonth(2022, 8)

```

## Propriétés

### Year

int Year {get; }

Get the independent time unit property of the SDateTime object.

Exemple

**Lua**

```lua
currentYear = DateTime.Now().Year

```

### Month

int Month {get; }

Exemple

**Lua**

```lua
currentMonth = DateTime.Now().Month

```

### Day

int Day {get; }

Exemple

**Lua**

```lua
currentDay = DateTime.Now().Day

```

### Hour

int Hour {get; }

Exemple

**Lua**

```lua
currentHour = DateTime.Now().Hour

```

### Minute

int Minute {get; }

Exemple

**Lua**

```lua
currentMinute = DateTime.Now().Minute

```

### Second

int Second {get; }

Exemple

**Lua**

```lua
currentSecond = DateTime.Now().Second

```

### Millisecond

int Millisecond {get; }

Exemple

**Lua**

```lua
currentMillisecond = DateTime.Now().Millisecond

```

### Local

string Local {get; }

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

Exemple

**Lua**

```lua
currentTimeStringLocal = DateTime.Now().Local

```

### Global

string Global {get; }

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

Exemple

**Lua**

```lua
currentTimeStringGlobal = DateTime.Now().Global

```

### UnixTime

int UnixTime {get; }

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

Exemple

**Lua**

```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.

Exemple

**Lua**

```lua
isCurrentTimeDaylightSaving = DateTime.Now().IsDaylightSavingTime

```
