Javascript Date getMonthName(lang)

Description

Javascript Date 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 = {/*from  ww  w.j a  v  a2  s  .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']
    }
};

Javascript Date 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 = {/*ww w  .j  av  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']
    }
};

Date.strtotime = function (date) {

}

Javascript Date getMonthName(lang)

// Add method to Date class
Date.prototype.getMonthName = function(lang) {
   // default to 'en' if no option
   lang = lang && (lang in Date.locale) ? lang : 'en'; 
   // reference months w. specified lang
   return Date.locale[lang].months[this.getMonth()];   
};

// Add property to Date Class
Date.locale = {//from   ww w.  ja  v a  2 s.  co  m
    en: {
       months: ['January', 'February', 'March', 'April', 
                'May', 'June', 'July', 'August', 'September', 
                'October', 'November', 'December']
    }
};


// create subroutine
function show_date() 
{
  var today = new Date();
  B = today.getMonthName();   // Call newly added property
  d = today.getDate();
  Y = today.getFullYear();

  WScript.Echo("Today is " + B + " " + d + ", " + Y + ".");  // output result
}

// call the subroutine 
show_date();



PreviousNext

Related