The standard librarySlide 62 of 85
62timeThe standard library
Time
A time in Hive is a plain Int — 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. millisecond() is something else: a field of the current instant, 0 to 999.
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 stamp 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 now.
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.