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

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();
}

Leave a Comment