-1

if I console log the two I get the same result but for some reason the result of the third console is false which means there is some difference! Any help is appreciated.

 console.log(new Date());
 console.log(moment(new Date()).toDate());
 console.log(moment(new Date()).toDate() == new Date());

The following is the result I get on the console:

Wed Jul 08 2015 15:55:30 GMT-0500 (Central Daylight Time)
Wed Jul 08 2015 15:55:30 GMT-0500 (Central Daylight Time)
false
akash
  • 5
  • 1
  • 2

1 Answers1

1

You are comparing Date objects, but you should really be comparing their values:

console.log(moment(new Date()).toDate().getTime() == (new Date()).getTime());
console.log(+(moment(new Date()).toDate()) == +(new Date()));

More discussion on this here: Compare two dates with JavaScript

Community
  • 1
  • 1
Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194