Home > Web Front-end > JS Tutorial > Example analysis of calculating the month difference between two dates using js

Example analysis of calculating the month difference between two dates using js

coldplay.xixi
Release: 2020-06-13 12:58:25
forward
3180 people have browsed it

Example analysis of calculating the month difference between two dates using jsHow to calculate the month difference between two dates in js?

How many months is the difference between the two times?

//两个日期
var date1 = '2013-03-26';
var date2 = '2011-01-10';
// 拆分年月日
date1 = date1.split('-');
// 得到月数
date1 = parseInt(date1[0]) * 12 + parseInt(date1[1]);
// 拆分年月日
date2 = date2.split('-');
// 得到月数
date2 = parseInt(date2[0]) * 12 + parseInt(date2[1]);
var m = Math.abs(date1 - date2);
alert(m);
Copy after login

Recommended tutorial: "JS Tutorial"

The above is the detailed content of Example analysis of calculating the month difference between two dates using js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template