UMD Web Utilities Library
    Preparing search index...

    Function setLocalStorageTimestamp

    • Stores the current timestamp in localStorage

      Sets the current time (in milliseconds since epoch) to localStorage under the specified key. Useful for tracking when events occurred.

      Parameters

      • key: { key: string }

        The localStorage key to set

      Returns void

      // Store when user last visited
      setLocalStorageTimestamp({ key: 'last-visit' });

      // Later, retrieve and check the timestamp
      const lastVisit = getLocalStorageInt({ key: 'last-visit' });
      if (lastVisit) {
      const daysSince = (Date.now() - lastVisit) / (1000 * 60 * 60 * 24);
      console.log(`Last visited ${Math.floor(daysSince)} days ago`);
      }