我将日期存储到如下所示的本地存储中。存储日期和从本地存储中检索
JS:
var currentTime = new Date(); //get the current time.
//Clock in the time.
localStorage.time = currentTime;
当我尝试一段时间再取回使用...
var timeObj = new Date(localStorage.time);
var checkInDayOfMonth = timeObj.getUTCDate(); //returns 1-31
的timeObj不会有正确的日期时间,它反而显得有电流就好像它忽略了我发送的时间参数一样。
我正在使用getUTCDate来获取每月的一天。如果今天的价值与存储中的价值不同,我知道这是新的一天。
开幕谷歌Chrome检查显示存储在localStorage的这种格式的日期:
Wed Dec 11 2013 22:17:45 GMT-0800 (PST)
那是不是为日期构造一个可接受的格式?
如何正确存储和检索localStorage中的日期?
上面有错误,而且一个月前的当天,还一个月你需要说+ 1,因为它返回0-11 –