The standard librarySlide 63 of 86
63timeThe standard library
Time
A time in Hive is a plain Int of Unix milliseconds, so it needs no type of its own to pass around, store or compare, and the difference of two is how long passed between them.
now()reads the clock.timezone()is the zone's name, andtimezoneOffset()how far it is from UTC, in minutes east.format(time, template)writes a time in local time with a strftime-style template:%Y %y %m %d %H %I %M %S %p %j %A %a %B %b %Z %z, and%%for a%. An escape it does not know passes through as written.dateFrom(year, month, day)anddateTimeFrom(year, month, day, hour, minute, second)build a time in local time, a field out of range carrying into the next —dateFrom(2026, 3, 0)is the last day of February.year(),month(),day(),weekday()— 1 for Monday to 7 for Sunday —lastDayOfMonth(),hour(),minute(),second()andmillisecond()each read one field of the current instant.millisecond()is that field, 0 to 999, not a time.
The clock
proc main(): void {
stamp := hive.time.now()
echo hive.time.format(stamp, "%Y-%m-%d %H:%M")
echo hive.time.timezone()
echo hive.time.timezoneOffset()
}You can edit this program and run it here.Tab indents, Escape leaves the program, and Ctrl+Enter runs it.
A date you name
proc main(): void {
day := hive.time.dateFrom(2026, 9, 14)
echo hive.time.format(day, "%Y-%m-%d %A")
// Day 0 of March is the last day of February.
echo hive.time.format(hive.time.dateFrom(2026, 3, 0), "%Y-%m-%d")
// This month, from its first day to its last.
year := hive.time.year()
month := hive.time.month()
first := hive.time.dateFrom(year, month, 1)
last := hive.time.dateFrom(year, month, hive.time.lastDayOfMonth())
echo hive.time.format(first, "%d/%m") + " to " + hive.time.format(last, "%d/%m")
}You can edit this program and run it here.Tab indents, Escape leaves the program, and Ctrl+Enter runs it.
Output
Run a program to see what it prints here.