Search code examples
react-nativereact-native-iosasyncstorage

I am trying to store current date and time in asyncstorage, but the return value I get is a promise and I can't see the values


I tried passing the values as Json (key-pair values) but I don't get to to see the values in response.


Solution

  • To store current date and time in AsyncStorage you can use an async function,

    StoreDate = async () => {
      await AsyncStorage.setItem('date', new Date());
    };
    

    To retrieve stored date,

    retrieveDate = async () => {
        const value = await AsyncStorage.getItem('date');
    };