Retrieve the created time of Localstorage RRS feed

  • Question

  • User-257070954 posted


        Is there any way to get created time of localstorage variable by jquery?

    Monday, July 6, 2020 10:04 AM

All replies

  • User-474980206 posted

    no. just add another variable which has a timestamp.


    Monday, July 6, 2020 3:16 PM
  • User-939850651 posted

    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:

    //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

    Tuesday, July 7, 2020 6:35 AM