Javascript Date - set just the date, ignoring time?

后端 未结 4 643
梦毁少年i
梦毁少年i 2021-02-06 23:58

I have a bunch of objects, each of which has a timestamp, that I want to group by date, into a JSON object. The ultimate goal is something like this:

myObject =          


        
4条回答
  •  星月不相逢
    2021-02-07 00:04

    If you don't mind creating an extra date object, you could try:

    var tempDate = new Date(parseInt(item.timestamp, 10));
    var visitDate = new Date (tempDate.getUTCFullYear(), tempDate.getUTCMonth(), tempDate.getUTCDate());
    

    I do something very similar to get a date of the current month without the time.

提交回复
热议问题