Beta
Format the given date as the given type.
Note
If a string
is supplied to the date
parameter, it will be converted
to a Date
object before formatting. See parse
for details.
A string representation of the date.
The date to format.
Either a string specifying the type to format the date
as, or a DateTimeFormatterOptions
object.
Parse a date value, converting it to local time.
A date value passed as a string
may be converted as a date-only value
if type
is 'date', 'year', 'quarter', 'month' or 'week'. This
basically means returning dates as they are stored in the database, by
compensating for any time difference.
If the date value includes time but not time zone offset, it is always interpreted as local time.
A date value passed as a Date
is returned unmodified.
// Converting a saved date value to 2023-10-24 in local time
// The time component of the returned date object should be ignored.
const parsedDate = dateTimeFormatter.parse('2023-10-24T00:00:00.000Z', 'date');
// Parsing a date value as local time
const parsedDate = dateTimeFormatter.parse('2023-10-24 23:59:59', 'date');
// Parsing a date-time value including time zone offset
const parsedDate = dateTimeFormatter.parse('2023-10-24T13:00:00+02:00', 'time');
The date to parse.
A string specifying the type to parse the date as.
Service for formatting date and time values.