Home  >  Article  >  Web Front-end  >  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

零下一度
零下一度Original
2017-04-26 11:07:101644browse

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>

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!

Statement:
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