Functions
Timestamp Functions
Functions for working with the timestamps.
Generation and Formatting
These functions are used to generate timestamps and format them in a specific way.
timestamp
The time::timestamp function returns a UTC timestamp string in RFC 3339 format.
time::timestamp()
# Example Result: "2024-10-14T09:45:30Z"
formatdate
The time::format_date function converts a timestamp into a different time format.
time::format_date("DD MMM YYYY hh:mm ZZZ", "2023-05-15T16:30:00Z")
# Result: "15 May 2023 16:30 UTC"
time::format_date("EEEE, DD-MMM-YY hh:mm:ss ZZZ", "2023-05-15T16:30:00Z")
# Result: "Monday, 15-May-23 16:30:00 UTC"
time::format_date("EEE, DD MMM YYYY hh:mm:ss ZZZ", "2023-05-15T16:30:00-04:00")
# Result: "Mon, 15 May 2023 16:30:00 -0400"
time::format_date("MMM DD, YYYY", "2023-05-15T16:30:00Z")
# Result: "May 15, 2023"
time::format_date("HH:mmaa", "2023-05-15T16:30:00Z")
# Result: "04:30pm"
Manipulation and Comparison
These functions are used for comparing timestamps or performing operations on them.
add
The time::add function adds a duration to a timestamp, resulting in a new timestamp.
time::add("2023-06-01T12:00:00Z", "30m")
# Result: "2023-06-01T12:30:00Z"
compare
The time::compare function compares two timestamps and returns a number that denotes the ordering of the instants those timestamps represent.
time::compare("2023-06-01T12:00:00Z", "2023-06-01T12:00:00Z")
# Result: 0
time::compare("2023-06-01T12:00:00Z", "2023-06-01T13:00:00Z")
# Result: -1
time::compare("2023-06-01T13:00:00Z", "2023-06-01T12:00:00Z")
# Result: 1
time::compare("2023-06-01T13:00:00Z", "2023-06-01T12:00:00-01:00")
# Result: 0