Dates and times#
An instant is a point in time. Mathnote carries it as epoch milliseconds: the number of milliseconds since 1970-01-01T00:00:00Z. That is a plain number, so instants take part in ordinary arithmetic, and the functions below read and write it.
Read a date-like value#
parseDateTime turns a written date into an instant. It accepts epoch seconds or milliseconds, ISO 8601 strings, plain dates, clock times, and relative words.
parseDateTime("2017-01-14 20:09:50")
parseDateTime("2017-01-14T20:09:50.912Z")
parseDateTime("02/25/2017 01:16 PM")Interactive examples could not load. You can still copy the expressions.
Ten digits or fewer is read as epoch seconds, eleven or more as epoch milliseconds, so 1484524800 and 1484524800000 are the same instant. The written forms are 2017-01-14, 2017-01-14 20:09:50, 2017-01-14T20:09:50.912Z, 02/25/2017 01:16 PM, 25.02.2017 18:16, 08:00, 09:30 PM, today, tomorrow, yesterday, last Wednesday, and now. A clock time on its own means today, and a bare weekday means its next occurrence.
now gives the current instant.
Show an instant#
formatDateTime renders an instant in one of the named formats: iso, date, time, datetime, weekday, rfc, and human.
formatDateTime(parseDateTime("2017-01-14 20:09:50"), "iso")
formatDateTime(parseDateTime("2017-01-14 20:09:50"), "datetime")
formatDateTime(parseDateTime("2017-01-14 20:09:50"), "weekday")Interactive examples could not load. You can still copy the expressions.
An instant carries no time zone of its own — it is the same moment everywhere — so the time zone argument decides how it reads.
Choose a time zone#
The time zone argument defaults to UTC, so the same expression gives the same answer on every machine. Pass local for the device's own zone, a fixed offset such as +05:30, or an IANA name such as Europe/Amsterdam.
formatDateTime(parseDateTime("2017-01-14 20:09:50"), "datetime", "Asia/Tokyo")
formatDateTime(parseDateTime("2017-01-14 20:09:50"), "datetime", "+05:30")Interactive examples could not load. You can still copy the expressions.
A friendly name works when it matches exactly one zone, so New York finds America/New_York. A name that matches several zones is reported with its candidates rather than guessed. A time zone written inside the value wins over the argument, and an explicit offset in an ISO string wins over both.
timezones lists the names the app can resolve.
Snap to a calendar period#
startOf and endOf move an instant to the first or last moment of a day, month, or year in the given time zone. The month end follows the calendar, so it is the last moment of that month rather than a fixed length.
formatDateTime(startOf(parseDateTime("2024-03-15 13:37"), "month"), "date")
formatDateTime(endOf(parseDateTime("2024-03-15 13:37"), "month"), "datetime")Interactive examples could not load. You can still copy the expressions.
Measure a duration#
Because an instant is a number of milliseconds, a duration is the difference of two instants. Divide by the number of milliseconds in the unit you want — 86400000 for days, 3600000 for hours.
(parseDateTime("2025-01-01") - parseDateTime("2024-01-01")) / 86400000Interactive examples could not load. You can still copy the expressions.
Note that a plain number divided by a unit such as (1 day) gives the reciprocal dimension, because an instant is a plain count of milliseconds rather than a duration. Divide by the millisecond count instead.
Older names#
toEpoch and formatTime are compatibility aliases for parseDateTime and
formatDateTime: they accept the same arguments and return the same
results, so saved notes and existing expressions keep working unchanged.
Prefer the canonical names in new notes.
See also#
All functions lists every function with its syntax and an example.