DateTime class
From Catglobe Wiki
More actions
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