Better way of getting time in milliseconds in javascript?

前端 未结 5 1099
说谎
说谎 2021-01-30 05:06

Is there an alternative in JavaScript of getting time in milliseconds using the date object, or at least a way to reuse that object, without having to instantiate a new object e

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 05:25

    If you have date object like

    var date = new Date('2017/12/03');
    

    then there is inbuilt method in javascript for getting date in milliseconds format which is valueOf()

    date.valueOf(); //1512239400000 in milliseconds format
    

提交回复
热议问题