-
Notifications
You must be signed in to change notification settings - Fork 1
formatDate
Yousif Al-Raheem edited this page Aug 25, 2020
·
3 revisions
This utility reformats any date string to any desired format. To use it, pass a Date
object or string, input format and output format. If date passed is not valid, the function will return null
.
const date = "7/22/2019";
const result = formatDate(date);
console.log(result); // returns "22 juli 2022" as it's using Swedish locale by default
Param | Type | Description |
---|---|---|
date |
Date | string
|
The date object or string to be formatted |
format | Intl.DateTimeFormatOptions |
The output format. Default is { day: 'numeric', month: 'long', year: 'numeric' }
|
locale | string |
The locale. Default is sv-SE
|