Toggle menu
913
3.8K
30.2K
279.2K
Catglobe Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

DateTime class: Difference between revisions

From Catglobe Wiki
Tungocman (talk | contribs)
No edit summary
No edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{CGscriptClass_Template |Name=<nowiki>DateTime</nowiki> |Description=<nowiki>The DateTime object</nowiki> |Constructors= {{CGscriptConstructors_Template|Parameters=
{{CGscriptClass_Template
|Name=<nowiki>DateTime</nowiki>
|Description=<nowiki>The object behind the first class construct: `DateTime d = #2024-01-01#;`.</nowiki>
|InheritsFrom=Array|Constructors=
{{CGscriptConstructors_Template|Description=<nowiki>Now in UTC timezone</nowiki>}}
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to parse as a date, syntax is same as for constant values</nowiki>}}
{{CGscriptParameters_Template|Type=string|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to parse as a date, syntax is same as for constant values</nowiki>}}
|Description=<nowiki>New based on a string representation of a date</nowiki>}} |Methods= {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}} |Properties= {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}} {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}}}
|Description=<nowiki>New based on a string representation of a date</nowiki>}}
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=array|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to parse as a date</nowiki>}}
|Description=<nowiki>New based on a array representation of a date</nowiki>}}
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>Year</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Month</nowiki>|Description=<nowiki>Month</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Day</nowiki>|Description=<nowiki>Day</nowiki>}}
|Description=<nowiki>New based on year, month and day (current user's timezone)</nowiki>}}
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>Year</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Month</nowiki>|Description=<nowiki>Month</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Day</nowiki>|Description=<nowiki>Day</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Timezone</nowiki>|Description=<nowiki>Timezone ID</nowiki>}}
|Description=<nowiki>New based on year, month, day and timezone</nowiki>}}
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>Year</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Month</nowiki>|Description=<nowiki>Month</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Day</nowiki>|Description=<nowiki>Day</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Hour</nowiki>|Description=<nowiki>Hour</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Minute</nowiki>|Description=<nowiki>Minute</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Second</nowiki>|Description=<nowiki>Second</nowiki>}}
|Description=<nowiki>New based on year, month, day, hour, minute and second (current user's timezone)</nowiki>}}
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>Year</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Month</nowiki>|Description=<nowiki>Month</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Day</nowiki>|Description=<nowiki>Day</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Hour</nowiki>|Description=<nowiki>Hour</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Minute</nowiki>|Description=<nowiki>Minute</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Second</nowiki>|Description=<nowiki>Second</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Timezone</nowiki>|Description=<nowiki>Timezone ID</nowiki>}}
|Description=<nowiki>New based on year, month, day, hour, minute, second and timezone</nowiki>}}
|Methods=
{{CGscriptMethods_Template|ReturnType=number|Name=<nowiki>AsUnixtimeMillisecondsSince1970</nowiki>|Description=<nowiki>Return value as number of milliseconds since 1 / 1 1970</nowiki>}}
{{CGscriptMethods_Template|ReturnType=number|Name=<nowiki>AsUnixtimeSecondsSince1970</nowiki>|Description=<nowiki>Return value as number of seconds since 1/1 1970</nowiki>}}
{{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>CompareTo</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=DateTime|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to compare to</nowiki>}}
|Description=<nowiki>Compare to object. See ArrayConstant.OrderBy</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>addDays</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of days to add</nowiki>}}
|Description=<nowiki>Add days to this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>addHours</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of hours to add</nowiki>}}
|Description=<nowiki>Add hours to this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>addMinutes</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of minutes to add</nowiki>}}
|Description=<nowiki>Add minutes to this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>addMonths</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of months to add</nowiki>}}
|Description=<nowiki>Add months to this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>addSeconds</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of seconds to add</nowiki>}}
|Description=<nowiki>Add seconds to this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>addYears</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of years to add</nowiki>}}
|Description=<nowiki>Add years to this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>daysBetween</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=DateTime|Name=<nowiki>Second</nowiki>|Description=<nowiki>The second DateTime object</nowiki>}}
|Description=<nowiki>Returns the number of whole days between this and another DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>}}
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
{{CGscriptMethods_Template|ReturnType=number|Name=<nowiki>secondsBetween</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=DateTime|Name=<nowiki>Second</nowiki>|Description=<nowiki>The second DateTime object</nowiki>}}
|Description=<nowiki>Returns the total number of seconds between this and another DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to set</nowiki>}}
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>subtractDays</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of days to subtract</nowiki>}}
|Description=<nowiki>Subtract days from this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>subtractHours</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of hours to subtract</nowiki>}}
|Description=<nowiki>Subtract hours from this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>subtractMinutes</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of minutes to subtract</nowiki>}}
|Description=<nowiki>Subtract minutes from this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>subtractMonths</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of months to subtract</nowiki>}}
|Description=<nowiki>Subtract months from this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>subtractSeconds</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of seconds to subtract</nowiki>}}
|Description=<nowiki>Subtract seconds from this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=DateTime|Name=<nowiki>subtractYears</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Amount</nowiki>|Description=<nowiki>Number of years to subtract</nowiki>}}
|Description=<nowiki>Subtract years from this DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>toInvariant</nowiki>|Description=<nowiki>Converts this DateTime to an invariant-format string (yyyy-MM-dd HH:mm:ss)</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>toJson</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Type</nowiki>|Description=<nowiki>Output format: 0=DateTime (default), 1=DateOnly, 2=TimeOnly</nowiki>}}
|Description=<nowiki>Serialises to a JSON ISO 8601 string (0=DateTime, 1=DateOnly, 2=TimeOnly)</nowiki>}}
{{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>workDaysBetween</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=DateTime|Name=<nowiki>Second</nowiki>|Description=<nowiki>The second DateTime object</nowiki>}}
|Description=<nowiki>Returns the number of working days between this and another DateTime</nowiki>}}
{{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>workDaysBetween</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=DateTime|Name=<nowiki>Second</nowiki>|Description=<nowiki>The second DateTime object</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=array|Name=<nowiki>Holidays</nowiki>|Description=<nowiki>List of holiday DateTime objects</nowiki>}}
|Description=<nowiki>Returns the number of working days (excluding holidays) between this and another DateTime</nowiki>}}
|Properties=
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>AsArray</nowiki>|HasGetter=1|Obsolete=1
|Description=<nowiki>Return value as the array representation of a date</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Average</nowiki>|HasGetter=1|Description=<nowiki>Average of the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Day</nowiki>|HasGetter=1|Description=<nowiki>The day-of-month component (1–31)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Hour</nowiki>|HasGetter=1|Description=<nowiki>The hour component (0–23)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>IsoWeek</nowiki>|HasGetter=1|Description=<nowiki>The ISO 8601 week number (1–53)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>IsoWeekYear</nowiki>|HasGetter=1|Description=<nowiki>The ISO 8601 week-year (may differ from Year for dates near year boundaries)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Max</nowiki>|HasGetter=1|Description=<nowiki>Largest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Millisecond</nowiki>|HasGetter=1|Description=<nowiki>The millisecond component (0–999)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Min</nowiki>|HasGetter=1|Description=<nowiki>Smallest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Minute</nowiki>|HasGetter=1|Description=<nowiki>The minute component (0–59)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Month</nowiki>|HasGetter=1|Description=<nowiki>The month component (1–12)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Second</nowiki>|HasGetter=1|Description=<nowiki>The second component (0–59)</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Sum</nowiki>|HasGetter=1|Description=<nowiki>Sum of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Year</nowiki>|HasGetter=1|Description=<nowiki>The year component</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>dayOfWeek</nowiki>|HasGetter=1|Description=<nowiki>Return day of week (0=Sunday, 1=Monday, ..., 6=Saturday)</nowiki>}}
|StaticMethods=
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_fromInvariant</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>DateTime string</nowiki>|Description=<nowiki>The invariant datetime string to parse</nowiki>}}
|Description=<nowiki>Parses an invariant datetime string to a DateTime object, or Empty when the input is absent</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_fromInvariant</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>DateTime string</nowiki>|Description=<nowiki>The invariant datetime string to parse; pass empty together with the second argument to get min/max date</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool?|Name=<nowiki>if true and empty return maxdate or mindate</nowiki>|Description=<nowiki>When the string is empty: true returns MaxValue, false returns MinValue</nowiki>}}
|Description=<nowiki>Parses an invariant datetime string to a DateTime object, or Empty when both inputs are absent</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_fromJson</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>DateTime string</nowiki>|Description=<nowiki>The JSON datetime string to parse</nowiki>}}
|Description=<nowiki>Deserialises a JSON datetime string to a DateTime array, or Empty when the input is absent</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_fromJson</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>DateTime string</nowiki>|Description=<nowiki>The JSON datetime string to parse; pass empty together with the second argument to get min/max date</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool?|Name=<nowiki>if true and empty return maxdate or mindate</nowiki>|Description=<nowiki>When the string is empty: true returns MaxValue, false returns MinValue</nowiki>}}
|Description=<nowiki>Deserialises a JSON datetime string to a DateTime array, or Empty when both inputs are absent</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_getLastDateOfMonth</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>The year (e.g. 2024)</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Month</nowiki>|Description=<nowiki>The month number (1-12)</nowiki>}}
|Description=<nowiki>Get the last date of the specified month</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_getWeekEnd</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>The year (e.g. 2024)</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Week</nowiki>|Description=<nowiki>The week number (1-53)</nowiki>}}
|Description=<nowiki>Get the end day of the specified week and year</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_getWeekStart</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>The year (e.g. 2024)</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Week</nowiki>|Description=<nowiki>The week number (1-53)</nowiki>}}
|Description=<nowiki>Get the start day of the specified week and year</nowiki>}}
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>DateTime_isLeapYear</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Year</nowiki>|Description=<nowiki>The year (e.g. 2024)</nowiki>}}
|Description=<nowiki>Determine whether the specified year is a leap year</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>DateTime_parse</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>DateTime string</nowiki>|Description=<nowiki>The string to parse as a DateTime</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>DateTime format string</nowiki>|Description=<nowiki>The format string</nowiki>}}
|Description=<nowiki>Parse a DateTime string to a DateTime object with the specified format</nowiki>}}
}}
 
==== <span style="color:#a52a2a">'''Examples'''</span> ====


==== <span style="color:#a52a2a;">'''Examples'''</span>  ====
<source lang="javascript">
<source lang="javascript">
DateTime dt = new DateTime("2009/04/05");
//*Ex1
dt.ToString();
DateTime dt = new DateTime ();
print(dt.AsArray);//{2017,10,2,4,13,34,583,40,0}
//*Ex2
DateTime dt = new DateTime("2009/4/5");
print(dt.ToString());//2009-04-05 00:00:00
print(dt.AsArray);//{2009,4,5,0,0,0,0,14,0}
//*Ex3
DateTime dt = new DateTime({2017,10,2,4,13,34,583,40,0});
print(dt.ToString());//2017-10-02 04:13:34
print(dt.AsUnixtimeMillisecondsSince1970());//1506917614583
print(dt.AsUnixtimeSecondsSince1970());//1506917614
 
</source>
</source>

Latest revision as of 10:23, 20 April 2026

DateTime


The object behind the first class construct: `DateTime d = #2024-01-01#;`.

Parent class

Inherits from Array

Constructors

  • () - Now in UTC timezone
  • (string value "Value to parse as a date, syntax is same as for constant values") - New based on a string representation of a date
  • (array value "Value to parse as a date") - New based on a array representation of a date
  • (int Year "Year", int Month "Month", int Day "Day") - New based on year, month and day (current user's timezone)
  • (int Year "Year", int Month "Month", int Day "Day", int Timezone "Timezone ID") - New based on year, month, day and timezone
  • (int Year "Year", int Month "Month", int Day "Day", int Hour "Hour", int Minute "Minute", int Second "Second") - New based on year, month, day, hour, minute and second (current user's timezone)
  • (int Year "Year", int Month "Month", int Day "Day", int Hour "Hour", int Minute "Minute", int Second "Second", int Timezone "Timezone ID") - New based on year, month, day, hour, minute, second and timezone

Methods

  • number AsUnixtimeMillisecondsSince1970() - Return value as number of milliseconds since 1 / 1 1970
  • number AsUnixtimeSecondsSince1970() - Return value as number of seconds since 1/1 1970
  • int CompareTo(DateTime value "Value to compare to") - Compare to object. See ArrayConstant.OrderBy
  • string ToString() - The string representation of the object.
  • DateTime addDays(int Amount "Number of days to add") - Add days to this DateTime
  • DateTime addHours(int Amount "Number of hours to add") - Add hours to this DateTime
  • DateTime addMinutes(int Amount "Number of minutes to add") - Add minutes to this DateTime
  • DateTime addMonths(int Amount "Number of months to add") - Add months to this DateTime
  • DateTime addSeconds(int Amount "Number of seconds to add") - Add seconds to this DateTime
  • DateTime addYears(int Amount "Number of years to add") - Add years to this DateTime
  • int daysBetween(DateTime Second "The second DateTime object") - Returns the number of whole days between this and another DateTime
  • object this[] { get; }(int index "Index") - Backward-compatible indexer
  • number secondsBetween(DateTime Second "The second DateTime object") - Returns the total number of seconds between this and another DateTime
  • Empty this[] { get; }(int index "Index", object value "Value to set") - Backward-compatible indexer
  • DateTime subtractDays(int Amount "Number of days to subtract") - Subtract days from this DateTime
  • DateTime subtractHours(int Amount "Number of hours to subtract") - Subtract hours from this DateTime
  • DateTime subtractMinutes(int Amount "Number of minutes to subtract") - Subtract minutes from this DateTime
  • DateTime subtractMonths(int Amount "Number of months to subtract") - Subtract months from this DateTime
  • DateTime subtractSeconds(int Amount "Number of seconds to subtract") - Subtract seconds from this DateTime
  • DateTime subtractYears(int Amount "Number of years to subtract") - Subtract years from this DateTime
  • string toInvariant() - Converts this DateTime to an invariant-format string (yyyy-MM-dd HH:mm:ss)
  • string toJson(int Type "Output format: 0=DateTime (default), 1=DateOnly, 2=TimeOnly") - Serialises to a JSON ISO 8601 string (0=DateTime, 1=DateOnly, 2=TimeOnly)
  • int workDaysBetween(DateTime Second "The second DateTime object") - Returns the number of working days between this and another DateTime
  • int workDaysBetween(DateTime Second "The second DateTime object", array Holidays "List of holiday DateTime objects") - Returns the number of working days (excluding holidays) between this and another DateTime

Properties

  • array AsArray { get; } - Return value as the array representation of a date
  • number Average { get; } - Average of the objects in the Array object. Can only use if all the elements are of type Number
  • int Day { get; } - The day-of-month component (1–31)
  • int Hour { get; } - The hour component (0–23)
  • int IsoWeek { get; } - The ISO 8601 week number (1–53)
  • int IsoWeekYear { get; } - The ISO 8601 week-year (may differ from Year for dates near year boundaries)
  • number Max { get; } - Largest of all the objects in the Array object. Can only use if all the elements are of type Number
  • int Millisecond { get; } - The millisecond component (0–999)
  • number Min { get; } - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number
  • int Minute { get; } - The minute component (0–59)
  • int Month { get; } - The month component (1–12)
  • string ObjectTypeName { get; } - The name of the type of object.
  • int Second { get; } - The second component (0–59)
  • number Sum { get; } - Sum of all the objects in the Array object. Can only use if all the elements are of type Number
  • TypeInformation TypeInformation { get; } - Get information about this class.
  • int Year { get; } - The year component
  • int dayOfWeek { get; } - Return day of week (0=Sunday, 1=Monday, ..., 6=Saturday)

Static Methods

  • array DateTime_fromInvariant(string DateTime string "The invariant datetime string to parse") - Parses an invariant datetime string to a DateTime object, or Empty when the input is absent
  • array DateTime_fromInvariant(string DateTime string "The invariant datetime string to parse; pass empty together with the second argument to get min/max date", bool? if true and empty return maxdate or mindate "When the string is empty: true returns MaxValue, false returns MinValue") - Parses an invariant datetime string to a DateTime object, or Empty when both inputs are absent
  • array DateTime_fromJson(string DateTime string "The JSON datetime string to parse") - Deserialises a JSON datetime string to a DateTime array, or Empty when the input is absent
  • array DateTime_fromJson(string DateTime string "The JSON datetime string to parse; pass empty together with the second argument to get min/max date", bool? if true and empty return maxdate or mindate "When the string is empty: true returns MaxValue, false returns MinValue") - Deserialises a JSON datetime string to a DateTime array, or Empty when both inputs are absent
  • array DateTime_getLastDateOfMonth(int Year "The year (e.g. 2024)", int Month "The month number (1-12)") - Get the last date of the specified month
  • array DateTime_getWeekEnd(int Year "The year (e.g. 2024)", int Week "The week number (1-53)") - Get the end day of the specified week and year
  • array DateTime_getWeekStart(int Year "The year (e.g. 2024)", int Week "The week number (1-53)") - Get the start day of the specified week and year
  • bool DateTime_isLeapYear(int Year "The year (e.g. 2024)") - Determine whether the specified year is a leap year
  • array DateTime_parse(string DateTime string "The string to parse as a DateTime", string DateTime format string "The format string") - Parse a DateTime string to a DateTime object with the specified format

Examples

//*Ex1
DateTime dt = new DateTime ();
print(dt.AsArray);//{2017,10,2,4,13,34,583,40,0}
//*Ex2
DateTime dt = new DateTime("2009/4/5");
print(dt.ToString());//2009-04-05 00:00:00
print(dt.AsArray);//{2009,4,5,0,0,0,0,14,0}
//*Ex3
DateTime dt = new DateTime({2017,10,2,4,13,34,583,40,0});
print(dt.ToString());//2017-10-02 04:13:34
print(dt.AsUnixtimeMillisecondsSince1970());//1506917614583
print(dt.AsUnixtimeSecondsSince1970());//1506917614