<script>
Date.isLeapYear = function (year) {
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
};
Date.getDaysInMonth = function (year, month) {
return [31, (Date.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
};
Date.prototype.isLeapYear = function () {
return Date.isLeapYear(this.getFullYear());
};
Date.prototype.getDaysInMonth = function () {
return Date.getDaysInMonth(this.getFullYear(), this.getMonth());
};
Date.prototype.addMonths = function (value) {
var n = this.getDate();
this.setDate(1);
this.setMonth(this.getMonth() + value);
this.setDate(Math.min(n, this.getDaysInMonth()));
return this;
};
var myDate = new Date("11/31/2012");
var result = myDate.addMonths(3);
console.log(myDate);
</script>
Monday, September 4, 2023
Add Date / Month / with difference Years
Subscribe to:
Post Comments (Atom)
Dunia Programmer: Setiap Orang Punya Spesialisasinya, Lebih dari Sekadar Frontend dan Backend
Ketika mendengar kata programmer, kebanyakan orang mungkin langsung membaginya menjadi dua kategori, yaitu Frontend Developer dan Backend De...
-
Dari Belajar Programming, Bisakah Kita Memahami Penciptaan Alam Semesta? Sabar dulu. Dari judulnya mungkin terdengar seperti saya akan memba...
-
< html lang = "en" > < head > < meta charset = "UTF-8" > < meta http-equiv = "X-UA-...
-
Barcode Generator Vanilla.js & Html < img id = "barcode" ></ img > < p >< button onclick = " down...
No comments:
Post a Comment