Skip to content

Instantly share code, notes, and snippets.

@alex-gist
Forked from rwbaker/dateExtend.js
Created March 12, 2012 16:47

Revisions

  1. alex-gist revised this gist Mar 12, 2012. No changes.
  2. @rwbaker rwbaker created this gist Oct 17, 2011.
    22 changes: 22 additions & 0 deletions dateExtend.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    //Extend Date to have a few extra fatures
    Date.dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    Date.monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    Date.prototype.dayNames = Date.dayNames;
    Date.prototype.monthNames = Date.monthNames;

    Date.prototype.getDayName = function() {
    return this.dayNames[this.getDay()];
    };
    Date.prototype.getDayNameAbbr = function() {
    return this.getDayName().slice(0,4);
    };
    Date.prototype.getMonthName = function() {
    return this.monthNames[this.getMonth()];
    };
    Date.prototype.getMonthNameAbbr = function() {
    if ( this.getMonth() === 8) {
    return this.getMonthName().slice(0,4); //SEPT looks better than SEP :)
    } else {
    return this.getMonthName().slice(0,3);
    };
    };