Skip to content

Instantly share code, notes, and snippets.

@kennycason
Last active April 7, 2018 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennycason/d9c1b11b37f428133b97d33df09c3ced to your computer and use it in GitHub Desktop.
Save kennycason/d9c1b11b37f428133b97d33df09c3ced to your computer and use it in GitHub Desktop.
getMonth.js (example)
function monthName() {
switch (new Date().getMonth()) {
case 0:
return "January";
case 1:
return "February";
case 2:
return "March";
case 3:
return "April";
case 4:
return "May";
case 5:
return "June";
case 6:
return "July";
case 7:
return "August";
case 8:
return "September";
case 9:
return "October";
case 10:
return "November";
case 11:
return "December";
}
return "Unknown";
}
const monthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
function monthName() {
return monthNames[new Date().getMonth()];
}
@kennycason
Copy link
Author

Note that there are other libraries via ECMAScript and 3rd party that makes this even easier. but the above are pure old school JS ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment