<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)
Set Cookie dan Remove Cookie dengan php vanilla.js
< html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport...
-
<html> <head> <title>Convert Image to Base64</title> </head> <body> <h2> Convert Ima...
-
Javascript ES6 Untuk Kali ini Coba Nge-Share Upload Foto dengan Vanilla Javascript dengan 2 method. method pertama dengan menggunakan n...
-
< html lang = "en" > < head > < meta charset = "UTF-8" > < meta http-equiv = "X-UA-...
No comments:
Post a Comment