How to get date without time in existing momentjs object?

萝らか妹 提交于 2020-01-12 15:17:50

问题


Let's say I have momentjs object like the following:

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

How could I get clone and get new momentjs object without time?


回答1:


With moment version 1.7 and above, just use startOf method.

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

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




回答2:


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

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

You'll now have two independent momentjs objects date and date2



来源:https://stackoverflow.com/questions/23758345/how-to-get-date-without-time-in-existing-momentjs-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!