码迷,mamicode.com
首页 > 其他好文 > 详细

获取一组时间中的最近的日期

时间:2017-06-30 15:36:22      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:turn   logs   bsp   null   span   时间   获取   get   mon   

        function getLatelyDate(arrDate) {
            var arrMs = arrDate.map(function(time) {
                return new Date(time.replace(/\-/g, "\/")).getTime();
            }, this);
            var max = Math.max.apply(null, arrMs);
            var date = new Date(max);
            return `${date.getFullYear()}-${this.turn(date.getMonth()+1)}-${this.turn(date.getDate())}`;
        };
        function turn(str) {
            str = String(str);
            return str.length === 1 ? ‘0‘+str : str;
        };


        var time = getLatelyDate([‘2018-06-27‘, ‘2017-06-21‘, ‘2015-02-2‘, ‘2017-08-2‘, ‘2017-04-15‘]);
        console.log(time);    // 2018-06-27

 

获取一组时间中的最近的日期

标签:turn   logs   bsp   null   span   时间   获取   get   mon   

原文地址:http://www.cnblogs.com/sorrowx/p/7098524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!