Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

invalid date format TypeScript

$
0
0

I am passing in time values departureTime such as '12:00' here. Then I try to convert it into a date and perform a subtraction. However, the result of timeOfDeparture and then time till departure is invalid. How can I fix this and make everything in a uniform type?

    const timeNow = new Date();    console.log('TIME NOW', timeNow)    const timeOfDeparture = new Date(departureTime);    console.log('TIME of Departure', timeOfDeparture)    const timeTillDeparture = Math.floor((timeOfDeparture.valueOf() - timeNow.valueOf()) / 60000);    console.log('TIME TILL DEP', timeOfDeparture)

Example console logs:

TIME NOW Tue Oct 06 2020 15:47:35 GMT+0200 (Central European Summer Time)TIME of Departure Invalid DateTripTimes.tsx:17 TIME TILL DEP NaN

Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>