Categories
JavaScript Answers

How to remove seconds/ milliseconds from Date convert to ISO string with JavaScript?

Spread the love

Sometimes, we want to remove seconds/ milliseconds from Date convert to ISO string with JavaScript.

In this article, we’ll look at how to remove seconds/ milliseconds from Date convert to ISO string with JavaScript.

How to remove seconds/ milliseconds from Date convert to ISO string with JavaScript?

To remove seconds/ milliseconds from Date convert to ISO string with JavaScript, we use the setSeconds method.

For instance, we write

const d = new Date();
d.setSeconds(0, 0);
console.log(d.toISOString());

to call setSeconds on date d to set its seconds and milliseconds to 0.

And then we call toISOString to return the ISO string from the date.

Conclusion

To remove seconds/ milliseconds from Date convert to ISO string with JavaScript, we use the setSeconds method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *