Skip to content

Time

The @std/time module provides time creation, parsing, formatting, and date arithmetic.

import time from "@std/time"
let now = time.now()
println(now.format("Y-m-d H:i:s"))
NameKindDescription
TimestructTime instance type.
nowfunctionReturns the current time.
parsefunctionParses a time string with a format.
parseAnyfunctionParses a string or Unix timestamp into a Time.

Returns the current time as a Time value.

import time from "@std/time"
let current = time.now()
println(current)
println(current.unix)

Parses a time value using a Nubo time format string.

Arguments:

NameTypeDescription
formatstringFormat pattern.
valuestringTime string to parse.

Returns: Time

import time from "@std/time"
let date = time.parse("Y-m-d", "2026-04-27")
println(date.format("Y/m/d"))

Parses a time from either a string or an integer Unix timestamp.

Arguments:

NameTypeDescription
time`stringint`

Returns: Time

import time from "@std/time"
let fromText = time.parseAny("2026-04-27T12:00:00Z")
let fromUnix = time.parseAny(1714219200)
println(fromText)
println(fromUnix)

Time values expose fields and methods for formatting and date arithmetic.

NameKindDescription
unixintUnix time stored as nanoseconds.
formatfunctionFormats the time.
addfunctionAdds seconds or another Time value.
substractfunctionSubtracts seconds or another Time value.
addDaysfunctionAdds days.
addMonthsfunctionAdds months.
addYearsfunctionAdds years.
yearfunctionReturns the year.
monthfunctionReturns the month number.
dayfunctionReturns the day of month.
hourfunctionReturns the hour.
minutefunctionReturns the minute.
secondfunctionReturns the second.
import time from "@std/time"
let now = time.now()
let tomorrow = now.addDays(1)
let nextMonth = now.addMonths(1)
let nextYear = now.addYears(1)
println(tomorrow.format("Y-m-d"))
println(nextMonth.month())
println(nextYear.year())

Time.format uses Nubo format tokens that are mapped internally.

TokenMeaningExample
Y4 digit year2026
y2 digit year26
FFull month nameApril
MShort month nameApr
mMonth with leading zero04
nMonth without leading zero4
dDay with leading zero27
jDay without leading zero27
DShort weekdayMon
lFull weekdayMonday
H24-hour hour with leading zero15
G24-hour hour15
h12-hour hour with leading zero03
g12-hour hour3
iMinutes04
sSeconds05
AUppercase AM/PMPM
aLowercase am/pmpm
TTimezone abbreviationUTC
ZTimezone offset+0000
cISO 8601 format2026-04-27T12:00:00+00:00
rRFC 2822 formatMon, 27 Apr 2026 12:00:00 +0000
import time from "@std/time"
let now = time.now()
println(now.format("Y-m-d H:i:s"))
println(now.format("l, F j, Y"))
println(now.format("c"))

Use \ to escape a format character.

import time from "@std/time"
let now = time.now()
println(now.format("Y-m-d \\a\\t H:i:s"))