What\'s the main difference between:
dt = new Date();
ms = Date.parse(dt);
and
dt = new Date();
ms = dt.getTime();
<
Though it's an old post, I'll leave my answer for someone who visit here later than me.
dt = new Date();
// often false, occasionally true
Date.parse(dt) === dt.getTime()
This is because you will lose the information about milliseconds when you do dt.toString()
which is internally called by Date.parse(dt)
. At least for Chrome (63.0.3239.84) and Firfox Quantum (57.0.3), they implement the toString()
method of Date object like this way. You can try the following example yourself.
dt = new Date('2018.1.1 01:01:01.001')
dt.getTime() // 1514739661001
Date.parse(dt) // 1514739661000
Date.parse(dt)
equals to dt.getTime()
only if dt
is captured at the moment that millisecond equals 0.