使用JavaScript的连续日期之间的日期差

时间:2018-07-18 12:24:16

标签: javascript arrays

我在类似数组中的日期

dates=[18-06-2018,19-06-2018,20-06-2018,21-06-2018,25-06-2018]

我需要这样的输出

from date:18-06-2018
to date:21-06-2018

from date:25-06-2018
to date:25-06-2018

我该如何实现

1 个答案:

答案 0 :(得分:0)

尝试一下:-

dates=['18-06-2018','19-06-2018','20-06-2018','21-06-2018','25-06-2018']
console.log('From date:'+dates[0]+'\n'+'to date:'+dates[3]);
console.log('From date:'+dates[4]+'\n'+'to date:'+dates[4]);