how to get min or max dates from a list of dates using moment.js?

前端 未结 2 364
不思量自难忘°
不思量自难忘° 2020-12-29 18:59

I want to have the max date from the list of dates given in the handleClick function. How to find the max date from the list of dates using moment.j

相关标签:
2条回答
  • 2020-12-29 19:32

    You can use moment.max function :

    let moments = this.state.dates.map(d => moment(d)),
        maxDate = moment.max(moments)
    
    0 讨论(0)
  • 2020-12-29 19:35

    Sort them with a custom compartor, then select the first one (or last, try it out);

       array.sort(function(d1, d2) {
           return moment(d1).isBefore(moment(d2));
            });
    
    0 讨论(0)
提交回复
热议问题