如何获得条件的日期> 24小时

时间:2017-07-24 10:53:19

标签: javascript date datetime comparison string-comparison

假设我有一个字段已解决。时间。 resolved.time =" 07/06/17 14:19:39"

我想在这样的javascript上写一个条件:

if resolved.time>24 hours{
print("true");
}
else
{
print("false");
}

我如何写这个条件"如果已解决。时间> 24小时"在JS? 感谢任何帮助。

谢谢和问候, Okik

1 个答案:

答案 0 :(得分:-1)

let resolved = {}
resolved.time = "07/06/17 14:19:39"

// convert resolved.time to milliseconds
const time = (new Date(resolved.time)).getTime()

const dayInMs = 24 * 60 * 60 * 1000


// check if duration between now and `time is greater than 24h 
if (Date.now() - time > dayInMs) {
  console.log("true");
} else {
  console.log("false");
}