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 = '2016-05-12'; 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!