Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Created March 20, 2022 02:30
Show Gist options
  • Save yano3nora/a42f338bc5fe164c903bead5009129b6 to your computer and use it in GitHub Desktop.
Save yano3nora/a42f338bc5fe164c903bead5009129b6 to your computer and use it in GitHub Desktop.
[js: Intl.DateTimeFormat] Built-in DateTime Formatter. #js
// 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