Created
February 5, 2015 21:46
-
-
Save shanejdonnelly/ddd2fd3f2c581d16bc87 to your computer and use it in GitHub Desktop.
Extend javascript Date object with handy day and month name methods.
This file contains 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
Date.locale = { | |
en: { | |
day_names: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], | |
day_names_short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | |
month_names: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], | |
month_names_short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | |
} | |
}; | |
//==================================================== | |
// | |
//Day Names | |
// | |
//==================================================== | |
Date.prototype.getDayName = function(lang) { | |
lang = lang && (lang in Date.locale) ? lang : 'en'; | |
return Date.locale[lang].day_names[this.getDay()]; | |
}; | |
Date.prototype.getDayNameShort = function(lang) { | |
lang = lang && (lang in Date.locale) ? lang : 'en'; | |
return Date.locale[lang].day_names_short[this.getDay()]; | |
}; | |
//==================================================== | |
// | |
//Month Names | |
// | |
//==================================================== | |
Date.prototype.getMonthName = function(lang) { | |
lang = lang && (lang in Date.locale) ? lang : 'en'; | |
return Date.locale[lang].month_names[this.getMonth()]; | |
}; | |
Date.prototype.getMonthNameShort = function(lang) { | |
lang = lang && (lang in Date.locale) ? lang : 'en'; | |
return Date.locale[lang].month_names_short[this.getMonth()]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment