2

I save a Date() in the AsyncStorage and when I open the app want to compare it to the current Date and check if at least n minutes are passed. I found a similar topic on the forum and tried to follow it

I wrote something like

try {
    const lastDate = await AsyncStorage.getItem('lastDate')
    if (lastDate !== null) {
        const currentDate = new Date()
        console.log(currentDate.getTime() - lastDate.getTime())
    }

But, I am getting an error telling me that getTime() is undefined.

Sravan
  • 1,891
  • 4
  • 23
  • 28
j.doe
  • 4,559
  • 6
  • 20
  • 31
  • what is `lastUpdateRequestDate `? – smnbbrv Feb 12 '18 at 13:25
  • I corrected the code – j.doe Feb 12 '18 at 13:27
  • So how is lastDate stored in the persistence layer? Is it already an Epoch Time (numeric) value? – Cogwizzle Feb 12 '18 at 14:18
  • diffDays = Math.round(Math.abs((new Date(currentDate).getTime() - new Date(lastDate).getTime()) / (oneDay))); Here currentDate and lastDate are in string format – Samiksha Jagtap Feb 19 '18 at 10:48
  • AsyncStorage.getItem('lastDate').then((lastDate) => { let CurrentDate = new Date(); lastDate= new Date(lastDate); var start = Math.floor(lastDate.getTime() / (3600 * 24 * 1000)); var end = Math.floor(CurrentDate.getTime() / (3600 * 24 * 1000)); var daysDiff = end - start; console.log(daysDiff); }) – Akshay I Nov 01 '18 at 06:28

0 Answers0