Created
March 20, 2022 02:30
-
-
Save yano3nora/a42f338bc5fe164c903bead5009129b6 to your computer and use it in GitHub Desktop.
[js: Intl.DateTimeFormat] Built-in DateTime Formatter. #js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat | |
// https://dev.classmethod.jp/articles/javascript-intl-datetimeformat-format/ | |
export const intlDateFormat = (date: number|Date) => { | |
const formatter = new Intl.DateTimeFormat('ja-JP', { | |
year: 'numeric', | |
month: '2-digit', | |
day: '2-digit', | |
weekday: 'short', | |
}) | |
return formatter.format(date).replace(/\//g, '-').split('(').join(' (') | |
} | |
intlDateFormat(new Date()) // 2022-03-19 (土) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment