I\'m trying to use moment to get the start of a day. I get different results with the following:
moment().startOf(\'day\'); //good
moment(new Date()).startO
I suggest to use format() to display the value of a moment object.
As the Internal Properties guide states:
Moment objects have several internal properties that are prefixed with
_
.The most commonly viewed internal property is the
_d
property that holds the JavaScript Date that Moment wrappers. Frequently, developers are confused by console output of the value of_d
....
To print out the value of a Moment, use
.format()
,.toString()
or.toISOString()
Here a snippet showing the correct results:
console.log(moment().startOf('day').format());
console.log(moment(new Date()).startOf('day').format());