As other member has said, you cannot directly obtain the time when the LocalStorage was first created.
Before adding another timestamp variable, I think you still need to determine whether the current LocalStorage contains data.
Just like this:
//check if there is data in localStorage if (Object.keys(localStorage).length === 0) {
//no data contains
var now = new Date();
localStorage.setItem("createtime", now);
}
Best regards,
Xudong Peng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
35 Points
156 Posts
Retrieve the created time of Localstorage
Jul 06, 2020 10:04 AM|binustrat|LINK
Hi,
Is there any way to get created time of localstorage variable by jquery?
All-Star
58254 Points
15674 Posts
Re: Retrieve the created time of Localstorage
Jul 06, 2020 03:16 PM|bruce (sqlwork.com)|LINK
no. just add another variable which has a timestamp.
Contributor
2110 Points
674 Posts
Re: Retrieve the created time of Localstorage
Jul 07, 2020 06:35 AM|XuDong Peng|LINK
Hi binustrat,
As other member has said, you cannot directly obtain the time when the LocalStorage was first created.
Before adding another timestamp variable, I think you still need to determine whether the current LocalStorage contains data.
Just like this:
Best regards,
Xudong Peng