How to get current date without time?

前端 未结 2 728
轻奢々
轻奢々 2021-01-07 23:05

I\'m trying to get the current date without the time and store it in a variable, within JavaScript. It needs to be without time as I\'m converting it to an epoch date, with

2条回答
  •  醉梦人生
    2021-01-07 23:39

    Try this:

    function dateToEpoch(thedate) {
        var time = thedate.getTime();
        return time - (time % 86400000);
    }
    

    or this:

    function dateToEpoch2(thedate) {
       return thedate.setHours(0,0,0,0);
    }
    

    Example : http://jsfiddle.net/chns490n/1/

    Reference: (Number) Date.prototype.setHours(hour, min, sec, millisec)

提交回复
热议问题