我很难找到合适的解决方案,所以我现在需要你的帮助。
date1 = "03/02/2012 09:51 pm"
date2 = "03/04/2012 06:00 pm"
将上述示例日期计算为diff天数。使用JavaScript。
答案 0 :(得分:2)
var date1 = Date.parse("03/02/2012 09:51 pm");
var date2 = Date.parse("03/04/2012 06:00 pm");
var dayDiff = (date2 / (1000*60*60*24)) - (date1 / (1000*60*60*24));
答案 1 :(得分:0)
moment.locale('en');
var from = moment("2016-04-14 23:30");
var until = moment("2016-04-14 23:45");
var untilDay = moment("2016-04-15 03:45");
var untilMonth = moment("2016-03-14 06:33");
$('body').append(from.to(until) + "<br>");
$('body').append(from.to(untilDay) + "<br>");
$('body').append(from.to(untilMonth) + "<br>");
&#13;
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/momentjs/2.10.6/moment-with-locales.min.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.10.6/locales.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
&#13;
答案 2 :(得分:-1)
删除原始帖子以修改并改变正确的答案
var date1 = new Date("2012-03-02");
var date2 = new Date("2012-04-15");
var daysDifference = new Date(date2 - date1);
var daysDifference = daysDifference/1000/60/60/24;
document.write(daysDifference);
亲自试试。