我有一个代表日期的字符串。我将它变成日期对象并提前一个月计算另一个日期。然后我想计算它们之间的天数差异,但我不知道为什么两者都变得相同而最终的冲击总是为零。我该怎么办?
var dateString = '2017-08-03';
var dateFrom = new Date(dateString);
console.log(dateFrom); //Thu Aug 03 2017 02:00:00 GMT+0200 (CEST)
var dateTo = new Date(dateFrom.setMonth(dateFrom.getMonth()+1));
console.log(dateTo); //Sun Sep 03 2017 02:00:00 GMT+0200 (CEST) (one month later)
console.log(dateFrom); //Sun Sep 03 2017 02:00:00 GMT+0200 (CEST)// (two dates turn into the same)
var difference = Math.floor((dateTo - dateFrom) / 86400000); // 0
答案 0 :(得分:0)
正在发生这种情况,因为在Sub Gender1()
'
' Gender1 Macro
'
' =IF(A2="Male","M","F")
Dim rCell As Range
Dim rRng As Range
Set rRng = Range("A2", Range("A2").End(xlDown))
For Each rCell In rRng.Cells
If rCell.Value = "Male" Then
result = "M"
rCell.Offset(0, 5).Select
ActiveCell.Value = result
ElseIf rCell.Value = "Female" Then
result = "F"
rCell.Offset(0, 5).Select
ActiveCell.Value = result
Else
result = "NULL"
rCell.Offset(0, 5).Select
ActiveCell.Value = result
End If
Next rCell
End Sub
中您实际上通过设置更改dateFrom是月份到下个月。你可以做这样的事情。
var dateTo = new Date(dateFrom.setMonth(dateFrom.getMonth()+1))
答案 1 :(得分:0)
但我不知道为什么两者都变得相同而且最终结果总是为零。
答案在线下
2017/08/03 11:28:26 [warn] 13799#0: *5 [lua] aescbc.lua:18: decrypt cipherBytes [9756eecad1842f844a6bf45ecc89d0ddd271bccb4bea7c84db04e2ed5ca84b8c] failed, client: 127.0.0.1, server: , request: "GET /aescbc HTTP/1.1", host: "127.0.0.1:8080"
您正尝试设置从月开始的月份,然后使用此更新日期创建新日期。如果你想达到欲望的结果,你可以使用下面的脚本。
dateFrom.setMonth(dateFrom.getMonth()+1)