3

How Do I Remove Seconds from Date Object and Reconvert back to Date?

let testDate = new Date(2020, 05, 03, 1, 2);

This answer converts to ISO String, I dont want that, but return an actual Date.

Remove Seconds/ Milliseconds from Date convert to ISO String.

  • You can't remove seconds from a Date object as it doesn't have any. A Date is just a time value, an offset in milliseconds since 1970-01-01T00:00:00Z. You can adjust the time value so that the seconds and milliseconds are zero using [*setSeconds*](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds), whether or not seconds are displayed depends formatting options when displaying it as a string (see [*How to format a JavaScript date*](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date?r=SearchResults&s=1|1450.4192)). – RobG Jun 04 '20 at 07:17

1 Answers1

1

var date = new Date();

date.setSeconds(0, 0);

console.log(date);
Nikita Madeev
  • 4,284
  • 9
  • 20