Hi Friends 👋,
Welcome to Infinitbility ❤️!
Today, we are going to learn How to convert date to number in typescript?, here we will use date built-in method Date.parse()
method to convert date to number format.
So, let’s see what is Date.parse()
method?
The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31).
Here, we will first create date object and store in variable, afer that we will use Date.parse()
to convert date to integer.
let’s dive in code…
const sampleDate = new Date(1994, 12, 10);
console.log(sampleDate);
console.log(Date.parse(sampleDate));
Well, when you run above code, you can able to see date converted in number format.
For now, let’s check the output.
Output
All the best 👍.