formatDateTime and parseDateTime
formatDateTime(value, { locale }) writes the date in numbers, as formatDate does, and the time in hours and minutes, or with seconds when it has seconds, such as 10/13/2026, 9:30 PM in en-US, 13.10.2026, 21:30 in de and 2026. 10. 13. 오후 9:30 in ko. parseDateTime(text, { locale }) reads typed text back into a Temporal.PlainDateTime, or returns null when the text is not one. Without locale, both use the runtime's own. Field.DateTimeInput reads and writes its text with them.
On this page
import { Code, DataList, Field, formatDateTime, Label, parseDateTime, Stack } from '@tounsoo/todae';
import { useId, useState } from 'react';
// What parseDateTime reads from the text, and how formatDateTime writes it back.
export default function DateTimeRoundTrip({ locale }: { locale: string }) {
const id = useId();
const [text, setText] = useState('2026-10-13 21:30');
const value = parseDateTime(text, { locale });
return (
<Stack.Root gap="condensed">
<Field.Group>
<Label.Root htmlFor={id}>Departs</Label.Root>
<Field.Root id={id}>
<Field.TextInput value={text} onChange={(event) => setText(event.target.value)} />
</Field.Root>
</Field.Group>
<DataList.Root aria-label="Round trip">
<DataList.Item>
<DataList.Term>parseDateTime</DataList.Term>
<DataList.Details>
<Code.Root>{value === null ? 'null' : value.toString()}</Code.Root>
</DataList.Details>
</DataList.Item>
<DataList.Item>
<DataList.Term>formatDateTime</DataList.Term>
<DataList.Details>
<Code.Root>{value === null ? 'null' : formatDateTime(value, { locale })}</Code.Root>
</DataList.Details>
</DataList.Item>
</DataList.Root>
</Stack.Root>
);
}
- parseDateTime
2026-10-13T21:30:00- formatDateTime
10/13/2026, 9:30 PM
What parseDateTime reads
It reads a date as parseDate does, with its year in full or as its last two digits, then a time as parseTime does, in the order the locale writes them, with or without the words the locale writes between them, such as Oct 13, 2026 at 9:30 PM or 10/13/2026 9:30 pm in en-US. The time needs its minutes, as in 21:30 or 2130, or a word, as in 9 pm, so an hour alone, as in 13.10.2026 21, is not read, and neither is a date without a time. Text that also reads as a month and day without a year and a time, as 10/13 12 05 pm in en-US, is not read.
Temporal
Todae ships no Temporal polyfill. Both use Temporal.PlainDateTime, so where the browser has no Temporal, the app loads a polyfill (see Native platform). A PlainDateTime has no time zone: it is the date and time on the user's clock. To store an instant, combine it with a time zone in your own code, such as value.toZonedDateTime(zone).
Accessible composition
Todae handles: Text in the locale you pass, or the runtime's own when you pass none.
You supply: A locale that matches the page's, and the same one for writing and reading. A message near the input when parseDateTime returns null.
Watch for: On a server with no locale, the text uses the server's locale. A value stored as if it were an instant: a PlainDateTime moves with the reader's clock, so add the time zone before you store a moment.
When to use
formatDateTime
When: Writing a date and time as text for a locale, such as into a text input of your own.
When not: A date and time with a weekday or a month name → Intl.DateTimeFormat. How long ago a time was → formatRelativeTime.
parseDateTime
When: Reading a date and time someone typed.
When not: Text in a fixed format such as 2026-10-13T09:30 → Temporal.PlainDateTime.from.
Props
| Name | Type | Description |
|---|---|---|
value Required | Temporal.PlainDateTime | The date and time to write. |
options.locale | string | The locale, such as ko. The runtime's own when not set. |
| Name | Type | Description |
|---|---|---|
text Required | string | The typed text. |
options.locale | string | The locale, such as ko. The runtime's own when not set. |