本地存储返回无效的日期格式 [英] local storage returning invalid format of date
问题描述
$ localStorage.doctorDateTime.push({
fullDate: new 日期(doctorDateTime)
});
我在新日期中传递了日期字符串然后将其保存到本地存储但是当我从本地存储它显示我这种格式:
2015-01-01T13:41:18.300Z
如果是console.log(doctorDateTime) 。它显示正确的日期字符串
localStorage.doctorDateTime.push({
fullDate: new 日期(doctorDateTime)
});
我在新日期传递了日期字符串然后将它保存到本地存储,但是当我从本地存储中检索它时,它显示我这种格式:
2015-01-01T13:41:18.300Z
$如果是console.log(doctorDateTime),则b $ b。它显示正确的日期字符串
此格式是有效的UTC格式。
您可以将其转换为任何格式并相应地使用。
Date.Parse
可用于此任务 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse [< a href =https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parsetarget =_ blanktitle =New Window> ^ ]
$localStorage.doctorDateTime.push({
fullDate : new Date(doctorDateTime)
});
I passed date string in new Date and then save it to local storage but when i retrieve it from local storage it showing me this format:
2015-01-01T13:41:18.300Z
while if console.log(doctorDateTime). it is showing right date string
localStorage.doctorDateTime.push({ fullDate : new Date(doctorDateTime) });
I passed date string in new Date and then save it to local storage but when i retrieve it from local storage it showing me this format:
2015-01-01T13:41:18.300Z
while if console.log(doctorDateTime). it is showing right date string
This format is a valid UTC format.
You can convert it into any format and use accordingly.
Date.Parse
can be used for this task - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse[^].
这篇关于本地存储返回无效的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!