Skip to main content

Command Palette

Search for a command to run...

LocalStorage With Timestamp ?

Published
1 min read
S

I love learning about technology and sharing that with others

Introduction

Problem Statement

we want to store some information on the localStorage and then we want to show the user when is the last time this information is updated, and once that is done we want to give user the functionality to again refresh and update the localStorage information and current timestamp

Solution

Create an object with data and timestamp

Store this in the Local Storage

Read from localStorage if Required parse the data and show the data and timestamp

if the user refresh update the data and the current timestamp

var object = {value: "value", timestamp: new Date().getTime()}
localStorage.setItem("key", JSON.stringify(object));

var object = JSON.parse(localStorage.getItem("key")),
  dateString = object.timestamp,
  now = new Date().getTime().toString();

compareTime(dateString, now); //to implement

How to do the above mentioned Steps in the JSP File ?

28 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)

LocalStorage With Timestamp ?