You can use the Intl.DateTimeFormat
for this (in supporting browsers).
You create a formatter with the options you want, in your case, the year should be "numeric", the month "short" and the day "numeric".
You can construct a date object using your ISO8601 string and then pass it to the formatter.
const formatter = new Intl.DateTimeFormat("en", { year: "numeric", month: "short", day: "numeric" });
const date = new Date("2012-10-16T17:57:28.556094Z");
formatter.format(date);
// => 'Oct 17, 2012'
Alternatively, you could set up an array of month names and use the getMonth
, getDay
and getFullYear
methods of Date
, like so:
const months = ["Jan", "Feb", ... , "Dec"];
const date = new Date("2012-10-16T17:57:28.556094Z");
`${months[date.getMonth()]} ${date.getDay()}, ${date.getFullYear()}`;
// => 'Oct 17, 2012'