Remove Seconds/ Milliseconds from Date convert to ISO String

前端 未结 9 1934
滥情空心
滥情空心 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:02

    While this is easily solvable with plain JavaScript (see RobG's answer), I wanted to show you the Moment.js solution since you tagged your questions as "momentjs":

    moment().seconds(0).milliseconds(0).toISOString();
    

    This gives you the current datetime, without seconds or milliseconds.

    Working example: http://jsbin.com/bemalapuyi/edit?html,js,output

    From the docs: http://momentjs.com/docs/#/get-set/

提交回复
热议问题