操作日期firefox vs chrome

operations with dates firefox vs chrome

本文关键字:chrome vs firefox 日期 操作      更新时间:2023-09-26

为什么这个减法适用于chrome而不适用于firefox:

if(((new Date()) - (new Date(res.last_connection)))/(1000*60)<12) //12 minits

res.last_connection是一个SQL格式的日期,javascript请求到服务器,它向数据库进行查询,并直接返回结果,类似于:"2015-10-28 23:13:35"。

我想的下一个解决方案是:

if(((new Date()).getTime() - (new Date(res.last_connection.replace(" ", "T"))).getTime())/(1000*60)<12)

空格的替换在firefox上有效,但在chrome上无效。chrome的新问题是时间提前了一个小时。

解决方案

经过长时间的打字和测试(我甚至在上做了一个账户),我想我找到了解决方案:

 if(((new Date()).getTime() - (new Date(res.last_connection.replace(/-/g,"/"))).getTime())/(1000*60)<12)

替换斜杠的脚本似乎有效!!:D

谢谢。