Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Convert an ISO Date String Into A Formatted Date In JavaScript

TODO : see new post with toLocaleString()

javascript
#!/usr/bin/env node

const months = [
  'January',
  'February',
  'March',
  'April',
  'May',
  'June',
  'July',
  'August',
  'September',
  'October',
  'November',
  'December',
]

const dateString = '2021-11-12T02:03:03-04:00'
const dateObject = new Date(dateString)

console.log(`${months[dateObject.getMonth()]} ${dateObject.getFullYear()}`)

Produces :

November 2021
#!/usr/bin/env node

const months = [
  'Jan.',
  'Feb.',
  'Mar.',
  'Apr.',
  'May',
  'Jun.',
  'Jul.',
  'Aug.',
  'Sept.',
  'Oct.',
  'Nov.',
  'Dec.',
]

const dateString = '2021-11-12T02:03:03-04:00'
const dateObject = new Date(dateString)

console.log(`${months[dateObject.getMonth()]} ${dateObject.getFullYear()}`)