Time
Last updated
Was this helpful?
Last updated
Was this helpful?
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
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.
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.