Home > Web Front-end > JS Tutorial > What you must know about how to get the number of days between dates using JS

What you must know about how to get the number of days between dates using JS

零下一度
Release: 2017-04-26 11:07:10
Original
1730 people have browsed it

This article mainly introduces the method of JS to simply obtain the number of days between dates, involving the conversion and calculation of javascript date and time related operation skills. Friends in need can refer to the following

The example of this article tells the simple method of obtaining the date with JS The method of difference in days is shared with everyone for your reference. The details are as follows:


<html>
<head>
<meta charset="utf-8">
<title>JS日期相差天数</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
var s1 = &#39;2016-05-12&#39;;
s1 = new Date(s1.replace(/-/g, "/"));
s2 = new Date();//当前日期:2017-04-24
var days = s2.getTime() - s1.getTime();
var time = parseInt(days / (1000 * 60 * 60 * 24));
document.write(time);
</SCRIPT>
</body>
</html>
Copy after login

The running result is: 347

The above is the detailed content of What you must know about how to get the number of days between dates using JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template