Nodejs Month Name Get getMonthName(lang)

Here you can find the source of getMonthName(lang)

Method Source Code

// create human readable day and 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()];
};

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()];
};

Date.locale = {//from  w  ww. j a v a  2s  .  c o m
    en: {
       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: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
       day_names_short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
    }
};

Related

  1. getMonthName()
    Date.prototype.getMonthName = function () {
      var monthNames = ["January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"
      ];
      return monthNames[this.getMonth()];
    };
    
  2. getMonthName(abbreviation)
    "use_strict";
    function getMonthName(index, abbreviation)
        abbreviation = (typeof abbreviation === 'boolean' && abbreviation);
        var abbrs = ['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec'],
            names = ['January','February','March','April','May','June','July','August','September','October','November','December'];
        return abbreviation ? abbrs[ index ] : names[ index ];
    Date.prototype.getMonthName = function(abbreviation)
    ...
    
  3. getMonthName(i)
    Date.prototype.getMonthName = function(i)
        "use strict";
        var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        if(i == months.length) 
            i = 0;
        return months[i];
    ...
    
  4. getMonthName(lang)
    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()];
    };
    Date.locale = {
    ...
    
  5. getMonthName(lang)
    Date.prototype.getMonthName = function(lang) {
      lang = lang || 'sv-SE';
      return this.toLocaleString(lang, {month: 'long'});
    };
    
  6. getMonthName(lang)
    Date.prototype.getMonthName = function(lang) {
        lang = lang && (lang in Date.locale) ? lang : 'de';
        return Date.locale[lang].month_names[this.getMonth()];
    };
    Date.locale = {
        de: {
            month_names: ['Januar', 'Februar', 'M?', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
            month_names_short: ['Jan', 'Feb', 'M?, 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
            day_names: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
    ...
    
  7. getMonthName(lang)
    Date.prototype.getMonthName = function (lang) {
      lang = lang && (lang in Date.locale) ? lang : 'en';
      return Date.locale[lang].monthNames[this.getMonth()];
    };
    Date.locale = {
      en: {
        monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    };
    
  8. getMonthNameShort(lang)
    Date.prototype.getMonthNameShort = function(lang) {
        lang = lang && (lang in Date.locale) ? lang : 'de';
        return Date.locale[lang].month_names_short[this.getMonth()];
    };
    Date.locale = {
        de: {
            month_names: ['Januar', 'Februar', 'M?', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
            month_names_short: ['Jan', 'Feb', 'M?, 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
            day_names: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
    ...
    
  9. getMonthNameShort(lang)
    Date.prototype.getMonthNameShort = function (lang) {
      lang = lang && (lang in Date.locale) ? lang : 'en';
      return Date.locale[lang].monthNamesShort[this.getMonth()];
    };