Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Last active April 29, 2018 17:02
Show Gist options
  • Save andreasvirkus/2fbe1d2977fc8115838bc6eaf2e49204 to your computer and use it in GitHub Desktop.
Save andreasvirkus/2fbe1d2977fc8115838bc6eaf2e49204 to your computer and use it in GitHub Desktop.
/*
A date formatter filter for SSGs/templating languages
*/
module.exports = (date) => {
const month = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
const ordinal = {
1 : "st",
2 : "nd",
3 : "rd",
21 : "st",
22 : "nd",
23 : "rd",
31 : "st"
}
const d = new Date(date)
return `${month[d.getMonth()]} ${d.getDate()}${ordinal[d.getDate()] || "th"} ${d.getUTCFullYear()}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment