Converts a day of the week integer to a day name - Node.js Date

Node.js examples for Date:Week

Description

Converts a day of the week integer to a day name

Demo Code


/**//from  ww w .j  av a2  s.  c  o m
 * Date.getDayName()
 * converts a day of the week integer to a day name
 *
 * @index
 *    an integer between 0-6 that represents the day of the
 *     week, *not the day of the month*
 */
Date.prototype.getDayName = function(index) {

  index = !index ? this.getDay() : index;

  var array = [
    'Sunday',
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday'
  ];

  return array[index];

};

Related Tutorials