js 获取数组中日期的最小值/最大值

数组

var dates = [];
dates.push(new Date("2011/06/25"))
dates.push(new Date("2011/06/26"))
dates.push(new Date("2011/06/27"))
dates.push(new Date("2011/06/28"))

代码用IE,FF,Chrome测试并正常工作:

var dates=[];
dates.push(new Date("2011/06/25"))
dates.push(new Date("2011/06/26"))
dates.push(new Date("2011/06/27"))
dates.push(new Date("2011/06/28"))
var maxDate=new Date(Math.max.apply(null,dates));
var minDate=new Date(Math.min.apply(null,dates));

**Use Spread Operators| ES6 **

let datesVar = [ 2017-10-26T03:37:10.876Z,
  2017-10-27T03:37:10.876Z,
  2017-10-23T03:37:10.876Z,
  2015-10-23T03:37:10.876Z ]
 
Math.min(...datesVar);

使用

                                    let startDateList = [];
                                    let endDateList = [];
                                    selectedIndices.forEach(item => {
                                        startDateList.push(new Date(object.startDate));
                                        endDateList.push(new Date(object.endDate));
                                    })
                                    let maxDate = utils.dateFormat(new Date(Math.max.apply(this,endDateList)),"YYYY-MM-DD");
                                    let minDate = utils.dateFormat(new Date(Math.min.apply(this,startDateList)),"YYYY-MM-DD");

转载于:https://my.oschina.net/u/2306318/blog/1835440

你可能感兴趣的:(时间处理,javascript,开发语言,ecmascript)