Difference Between Datetimes

后端 未结 2 1297
温柔的废话
温柔的废话 2021-01-28 17:56

I\'ve got a bit of code here that calculates the hours difference between two datetimes. Kind of at a loss here. Code is hit or miss and I\'m not sure why.

var          


        
2条回答
  •  萌比男神i
    2021-01-28 18:31

    The problem is that your parseInt() on date[1] is using the leading zero.

    return new Date(
        parseInt(date[2]), parseInt(date[0])-1, parseInt(date[1]),
        hm[0], parseInt(hm[1])
    );
    

    When you pass a date like 01/09/2011, the 09 is being parsed as 0, not 9.

提交回复
热议问题