time module
Last updated
Last updated
The original source for this documentation can be found here:
Module time is a Starlark module of time-related functions and types.
The Time and Duration types can be used using the following operators.
A Time represents an instant in time with nanosecond precision. The time type has the following attributes:
The year in which t occurs.
Month returns the month of the year specified by t.
Day returns the day of the month specified by t.
Hour returns the hour within the day specified by t, in the range [0, 23].
Minute returns the minute offset within the hour specified by t, in the range [0, 59].
Second returns the second offset within the minute specified by t, in the range [0, 59].
Nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999].
Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC. The result does not depend on the location associated with t. Unix-like operating systems often record time as a 32-bit count of seconds, but since the method here returns a 64-bit value it is valid for billions of years into the past or future.
Returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262). Note that this means the result of calling UnixNano on the zero Time is undefined. The result does not depend on the location associated with t.
A Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the largest representable duration to approximately 290 years.
Hours returns the duration as a floating point number of hours.
Minutes returns the duration as a floating point number of minutes.
Seconds returns the duration as a floating point number of seconds.
Milliseconds returns the duration as an integer millisecond count.
Microseconds returns the duration as an integer microsecond count.
Nanoseconds returns the duration as an integer nanosecond count.
The module defines the following constants:
nanosecond - A Duration representing one nanosecond.
microsecond - A Duration representing one microsecond.
millisecond - A duration representing one millisecond.
second - A Duration representing one second.
minute - A Duration representing one minute.
hour - A Duration representing one hour.
The module defines the following functions.
Reports whether loc is a valid time zone name.
Returns the current local time.
Returns the Time corresponding to yyyy-mm-dd hh:mm:ss + nsec nanoseconds in the appropriate zone for that time in the given location. All the parameters are optional.
Converts the given Unix time corresponding to the number of seconds and (optionally) nanoseconds since January 1, 1970 UTC into an object of type Time. For more details, refer to .
Parses the given duration string. For more details, refer to .
Parses the given time string using a specific time format and location. The expected arguments are a time string (mandatory), a time format (optional, set to RFC3339 by default, e.g. "2021-03-22T23:20:50.52Z") and a name of location (optional, set to UTC by default). For more details, refer to and .