簡體   English   中英

以 DD-MMM-YYYY 格式減去日期

[英]Subtract date with format DD-MMM-YYYY

我的日期格式為 DD-MMM-YYYY

我想從同樣格式的當前日期中減去這個日期。

我如何將它們彼此相減

var complaint_date =  15-JUL-2020
var current_date = 21-JUL-2020
var duration  = current_date - complaint_date // this is not working

您不能從彼此中減去字符串。 如果要減去日期,則需要將字符串轉換為Date object。

 var complaint_date = new Date("15-JUL-2020") var current_date = new Date("21-JUL-2020") var duration = current_date - complaint_date console.log(duration) // diff in milliseconds console.log(Math.round(Math.abs((duration) / (24 * 60 * 60 * 1000)))) // diff in days

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM