DateTime
Class containing a calendar date and time broken down into its components. For convenience, all attributes has aliases to match struct tm provided in libc.
All class attributes are settable.
Instance attributes
- second: int
- sec: int
- tm_sec: int
-
Seconds after the minute. Can be modified.
- minute: int
- min: int
- tm_min: int
-
Minutes after the hour. Can be modified.
- hour: integer
- tm_hour: integer
-
Hours since midnight. Can be modified.
- day: int
- mday: int
- tm_mday: int
-
Day of the month. Can be modified.
- month: int
- mon: int
- tm_mon: int
-
Months since January. Can be modified.
- year: int
- tm_year: int
-
Year. Can be modified.
- dayOfYear: int
- yday: int
- tm_yday: int
-
Days since January 1. Can be modified.
- dayOfWeek: int
- wday: int
- tm_wday: int
-
Days since Sunday. Can be modified.
- isDST: bool
- isdst: bool
- tm_isdst: bool
-
Daylight Saving Time flag. Can be modified.
- isUTC: bool
-
UTC flag. Can be modified.
- timestamp: int
-
UNIX time (number of seconds since epoch). Can be modified.
Instance methods
- format(format): void
-
Formats a timestamp, and returns a string according to given formatting rules.
Table 1. Parameters string
String
Formatting string - see this for available options http://www.cplusplus.com/reference/ctime/strftime/
ReturnFormatted time as a string.
time = DateTime(); println(time.format("%Y-%m-%d %H:%M")); //Will print: "2016-01-19 12:14" println(time.format("%Y-%m-%d %H:%M - timezone %Z - offset from UTC - %z")); //Will print: "2016-01-19 12:14 - timezone CET - offset from UTC - +0100"
Constructors
DateTime()-
Creates new DateTime object with current local time.
DateTime(timestamp)-
Creates new DateTime with provided local time in UNIX time format.
Table 2. Parameters timestamp
Integer
UNIX time (number of seconds since epoch).
DateTime(time, isUTC)-
Creates new DateTime object with provided time. Current time will be counted as UTC time if second parameter is true and as local time if second parameter is false.
Table 3. Parameters timestamp
Integer
UNIX time (number of seconds since epoch).
isUTC
Boolean
If provided time is in UTC.