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
- (DateTime 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
- DateTime DateTime_addDays(DateTime DateTime "The DateTime object to operate on", int Day "The number of days to add") - Add days to a DateTime object
- DateTime DateTime_addHours(DateTime DateTime "The DateTime object to operate on", int Hour "The number of hours to add") - Add hours to a DateTime object
- DateTime DateTime_addMinutes(DateTime DateTime "The DateTime object to operate on", int Minute "The number of minutes to add") - Add minutes to a DateTime object
- DateTime DateTime_addMonths(DateTime DateTime "The DateTime object to operate on", int Month "The number of months to add") - Add months to a DateTime object
- DateTime DateTime_addSeconds(DateTime DateTime "The DateTime object to operate on", int Second "The number of seconds to add") - Add seconds to a DateTime object
- DateTime DateTime_addYears(DateTime DateTime "The DateTime object to operate on", int Year "The number of years to add") - Add years to a DateTime object
- int DateTime_compare(DateTime Be compared DateTime "The DateTime to compare", DateTime To compare DateTime "The DateTime to compare against") - Compare two DateTime objects. Returns -1 (less), 0 (equal), or 1 (greater)
- int DateTime_dayOfWeek(DateTime DateTime "The DateTime object to operate on") - Return day of week for a DateTime object
- int DateTime_daysBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object") - Returns the number of whole days between two DateTime objects
- int DateTime_daysBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object", int? Timezone "Unused") - Returns the number of whole days between two DateTime objects
- DateTime 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
- DateTime 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 (in the current user's timezone), or Empty when both inputs are absent
- DateTime 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
- DateTime 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
- DateTime DateTime_getByYMD(int Year "Year", int Month "Month", int Day "Day") - Creates a DateTime array object from year, month and day
- DateTime DateTime_getByYMD(int Year "Year", int Month "Month", int Day "Day", int Timezone "Timezone ID") - Creates a DateTime array object from year, month, day and timezone
- DateTime DateTime_getByYMD(int Year "Year", int Month "Month", int Day "Day", int Hour "Hour", int Minute "Minute", int Second "Second") - Creates a DateTime array object from year, month, day, hour, minute and second
- DateTime DateTime_getByYMD(int Year "Year", int Month "Month", int Day "Day", int Hour "Hour", int Minute "Minute", int Second "Second", int Timezone "Timezone ID") - Creates a DateTime array object from year, month, day, hour, minute, second and timezone
- DateTime DateTime_getLastDateOfMonth(int Year "The year (e.g. 2024)", int Month "The month number (1-12)") - Get the last date of the specified month
- DateTime 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
- DateTime 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
- string DateTime_objToInvariant(DateTime DateTime "The DateTime object to convert; pass empty to get an Empty result") - Converts a DateTime object to an invariant-format string, or Empty if the input is empty
- DateTime 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
- number DateTime_secondsBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object") - Returns the total number of seconds between two DateTime objects
- number DateTime_secondsBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object", int? Timezone "Unused") - Returns the total number of seconds between two DateTime objects
- DateTime DateTime_subtractDays(DateTime DateTime "The DateTime object to operate on", int Day "The number of days to subtract") - Subtract days from a DateTime object
- DateTime DateTime_subtractHours(DateTime DateTime "The DateTime object to operate on", int Hour "The number of hours to subtract") - Subtract hours from a DateTime object
- DateTime DateTime_subtractMinutes(DateTime DateTime "The DateTime object to operate on", int Minute "The number of minutes to subtract") - Subtract minutes from a DateTime object
- DateTime DateTime_subtractMonths(DateTime DateTime "The DateTime object to operate on", int Month "The number of months to subtract") - Subtract months from a DateTime object
- DateTime DateTime_subtractSeconds(DateTime DateTime "The DateTime object to operate on", int Second "The number of seconds to subtract") - Subtract seconds from a DateTime object
- DateTime DateTime_subtractYears(DateTime DateTime "The DateTime object to operate on", int Year "The number of years to subtract") - Subtract years from a DateTime object
- string DateTime_toInvariant(DateTime DateTime "The DateTime object to convert; pass empty to get an Empty result") - Converts a DateTime array object to an invariant-format string, or Empty if the input is empty
- string DateTime_toJson(DateTime DateTime "The DateTime object to serialise; pass empty to get an Empty result") - Serialises a DateTime to a JSON ISO 8601 string
- string DateTime_toJson(DateTime DateTime "The DateTime object to serialise; pass empty to get an Empty result", int? Type "Output format: 0 = DateTime (default), 1 = DateOnly, 2 = TimeOnly") - Serialises a DateTime to a JSON ISO 8601 string (0=DateTime, 1=DateOnly, 2=TimeOnly)
- int DateTime_workDaysBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object") - Returns the number of working days (excluding weekends) between two DateTime objects
- int DateTime_workDaysBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object", array Holiday "List of holiday DateTime objects") - Returns the number of working days (excluding weekends and specified holidays) between two DateTime objects
- int DateTime_workDaysBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object", int? Timezone "Unused") - Returns the number of working days (excluding weekends) between two DateTime objects with optional timezone override
- int DateTime_workDaysBetween(DateTime First DateTime "The first DateTime object", DateTime Second DateTime "The second DateTime object", array Holiday "List of holiday DateTime objects", int? Timezone "Unused") - Returns the number of working days (excluding weekends and specified holidays) between two DateTime objects with optional timezone override
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