Time
Operators and functions for working with date and time (time type) are described here.
The time type has the following fields:
- int Year - year
- int Month - month
- int Day - day of month
- int Hour - hour
- int Minute - minute
- int Second - second
- bool UTC - if it is true, then it is UTC time, otherwise it is local time.
Operator | Result | Description |
time == time | bool | Returns true if the two time values are equal and false, otherwise. |
time > time | bool | Returns true if the first time is greater than the second and false, otherwise. |
time < time | bool | Returns true if the first time is less than the second and false, otherwise. |
time != time | bool | Returns true if the two time values are not equal and false, otherwise. |
time >= time | bool | Returns true if the first time is greater than or equal to the second and false, otherwise. |
time <= time | bool | Returns true if the first time is less than or equal to the second and false, otherwise. |
time = time | time | Assignment operator. |
The int function converts time value to a Unix time, the number of seconds elapsed since January 1, 1970 UTC and returns it.
The time function converts the given Unix time, sec seconds since January 1, 1970 UTC to time structure and returns it.
The AddHours function returns the time corresponding to adding the given number of hours to t. The hours parameter can be negative.
The Date function returns a structure of the time type with the specified date.
The DateTime function returns the time structure as local time. Also, you can initialize a time variable like this
time t = {Year: 2018, Month: 12, Day: 12}
The Days function returns the number of days in the month in which the specified time is located.
The Format function returns a textual representation of the time value formatted according to layout. It takes a string of tokens and replaces them with their corresponding values.
| Token | Output |
Year | YYYY | 2019 |
| YY | 19 |
Month | MMMM | January |
| MMM | Jan |
| MM | 01..12 |
| M | 1..12 |
Day | DD | 01..31 |
| D | 1..31 |
Day of Week | dddd | Monday |
| ddd | Mon |
AM/PM | PM | AM PM |
| pm | am pm |
Hour | HH | 00..23 |
| hh | 01..12 |
| h | 1..12 |
Minute | mm | 00..59 |
| m | 1..59 |
Second | ss | 00..59 |
| s | 1..59 |
Time Zone | tz | MST |
| zz | -0700 ... +0700 |
| z | -07:00 ... +07:00 |
The Now function returns the current local time.
The ParseTime function parses a formatted string and returns the time value it represents. The list of layout tokens is the same as in Format function.
run str {
time t &= ParseTime(`MMM D, YYYY at h:mmpm (zz)`, `Jun 7, 2019 at 6:05am (+0300)`)
time t1 &= ParseTime(`YY/MM/DD HH:mm:s`, `19/05/29 03:21:3`)
return Format(`YY/MM/DD HH:mm:ss zz`, UTC(t)) + Format(` YY/MM/DD HH:mm:ss`, UTC(t1))
}
// 19/06/07 03:05:00 +0000 19/05/29 03:21:03
The str converts the specified time to a string in the format YYYY-MM-DD HH:mm:ss.
The UTC function converts local time to UTC and returns a new time structure. If the time t was already UTC, then a copy of it is returned.
The Weekday function returns the day of the week specified by t. 0 - Sunday, 1 - Monday etc.
The YearDay function returns the day of the year specified by t.
Last modified 2yr ago