Created
September 5, 2016 20:25
-
-
Save anonymous/8124915bfe71da15f63ef9fdaac0d2b5 to your computer and use it in GitHub Desktop.
Date Extensions for Javascript
This file contains hidden or 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.prototype.clone = function () { | |
return new Date(this.valueOf()); | |
} | |
Date.prototype.addDays = function (days) { | |
var d = this.clone(); | |
d.setDate(d.getDate() + days); | |
return d; | |
} | |
Date.prototype.countDays = function (end) { | |
var start = this.getTime(); | |
return Math.round((end.getTime() - this.getTime()) / (24 * 60 * 60 * 1000)) | |
} | |
Date.prototype.countMonths = function (end) { | |
return (end.getFullYear() * 12 + end.getMonth()) - (this.getFullYear() * 12 + this.getMonth()); | |
} | |
Date.prototype.datePart = function () { | |
var d = this.clone(); | |
d.setHours(0, 0, 0, 0); | |
return d; | |
} | |
Date.prototype.weekIndexInMonth = function () { | |
return Math.ceil(this.getDate() / 7) - 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment