How to set Hours,minutes,seconds to Date which is in GMT

前端 未结 3 1664
执笔经年
执笔经年 2020-12-17 08:27

I have Date Object ,I wanted to clear HOUR,MINUTE and SECONDS from My Date.Please help me how to do it in Javascript. Am i doing wrong ?

var date = Date(\"         


        
3条回答
  •  我在风中等你
    2020-12-17 09:03

    According to MDN the setHours function actually takes additional optional parameters to set both minutes, seconds and milliseconds. Hence we may simply write

    // dateString is for example "Fri, 26 Sep 2014 18:30:00 GMT"
    function getFormattedDate(dateString) {
       var date = new Date(dateString);
       date.setHours(0, 0, 0);   // Set hours, minutes and seconds
       return date.toString();
    }
    

提交回复
热议问题