Skip to content

useDateFormat

Format a date-like object into a predefined or custom format.

Parameters

NameDescription
dateThe date-like object to format.
formatThe date format, either a predefined format ('DD/MM/YYYY') or a custom format string.

Returns

The formatted date as a string.

(date: DateLike, format: "DD/MM/YYYY" | Omit<string, "DD/MM/YYYY">) => string
(date: DateLike, format: "DD/MM/YYYY" | Omit<string, "DD/MM/YYYY">) => string

Examples

ts
useDateFormat(new Date(), 'DD/MM/YYYY') // 22/09/2023

useDateFormat(new Date(), 'dddd DD/MM') // Friday 22/09
useDateFormat(new Date(), 'DD/MM/YYYY') // 22/09/2023

useDateFormat(new Date(), 'dddd DD/MM') // Friday 22/09

Released under the GNU GPLv3 License.