Reference · Dates
now
signature
now() -> intWhat it does
The time now as milliseconds since 1970-01-01T00:00:00Z, an int: the clock for
measuring how long something took, for timestamps stored as numbers and for
max_age-style arithmetic. date.from_ms turns it into a
date-time and date.ms a date-time into it. It is the time
effect. For today's date or the time as text, see date.today
and date.now.
Examples
let t = now()print(type_of(t), len(str(t)), t > 1700000000000)print(date.from_ms(t) | date.valid("date-time"))output
int 13 truetrueEdge cases
- It is read each time it is called, so two calls in a row can differ by a few milliseconds and never go backwards within a program, as the system clock has it.
- Time in a component's state is read once:
let started = now()stays as it was, since values are not re-read; a clock is a state thateverysets. - Day arithmetic is plain: a day is
24 * 60 * 60 * 1000.
let a = now()sleep(5)let b = now()print(b >= a + 5)let day = 24 * 60 * 60 * 1000print((date.from_ms(now() + day) | date.date_in) == date.add_days(date.today(), 1))output
truetrueErrors
It takes no arguments and cannot fail; there is nothing to check.
print(now() - now() <= 0)output
trueChaining
print(now() | date.from_ms("Europe/Lisbon") | date.valid("date-time"))print(now() | date.from_ms | date.date_in | len)output
true10See also
date.now, date.today, date.from_ms, date.ms, sleep
Thread
Thread 0 posts
On now(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo