Remove Seconds/ Milliseconds from Date convert to ISO String

前端 未结 9 1919
滥情空心
滥情空心 2020-12-15 15:41

I have a date object that I want to

  1. remove the miliseconds/or set to 0
  2. remove the seconds/or set to 0
  3. Convert to ISO string

F

9条回答
  •  佛祖请我去吃肉
    2020-12-15 16:03

    There is no need for a library, simply set the seconds and milliseconds to zero and use the built–in toISOString method:

    var d = new Date();
    d.setSeconds(0,0);
    document.write(d.toISOString());

    Note: toISOString is not supported by IE 8 and lower, there is a pollyfil on MDN.

提交回复
热议问题