How to get date without time in existing momentjs object?

Say I have a momentjs object, for example:

var date = moment(new Date(2014,2,17,9,60)); 

How can I get a clone and get a new momentjs object without time?

+7
javascript date momentjs
source share
2 answers

As of version 1.7 and above, just use the startOf method.

 var date2 = date1.clone().startOf('day'); 

See http://momentjs.com/docs/#/manipulating/start-of/

+17
source share

The momentjs object will always store time, regardless of whether you use it. However, the following will clone from date to date2 and reset time:

 var date2 = date.clone().hour(0).minute(0).second(0).millisecond(0) 

Now you have two independent objects momentjs date and date2

+5
source share

All Articles