Last active
April 7, 2018 18:22
-
-
Save kennycason/d9c1b11b37f428133b97d33df09c3ced to your computer and use it in GitHub Desktop.
getMonth.js (example)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const monthNames = [ | |
"January", | |
"February", | |
"March", | |
"April", | |
"May", | |
"June", | |
"July", | |
"August", | |
"September", | |
"October", | |
"November", | |
"December" | |
]; | |
function monthName() { | |
return monthNames[new Date().getMonth()]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.