Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Convert an ISO Date String Into A Formatted Date In JavaScript

TODO: see new post with toLocaleString()

Code

#!/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:

Code

November 2021

Code

#!/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()}`)