Integer addition/subtraction issues with the Date object

后端 未结 2 2031
北荒
北荒 2021-01-28 13:41

I was playing around with the native Date object, and I realised that subtraction works (returns an integer representing the total number of miliseconds between the two dates),

2条回答
  •  执念已碎
    2021-01-28 14:01

    the + operator is overloaded for strings, - is not. You need to use

    var newVal=parseInt(new Date().getTime()) + 1000
    

提交回复
热议问题