Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
114 views
in Technique[技术] by (71.8m points)

js中多个时间,怎么取最小值

['2020-9-1','2020-9-2','2020-9-3']
怎么取最小的时间

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

转时间戳排序:

array.sort((a, b) => (new Date(a)).valueOf() - (new Date(b)).valueOf())[0];

或者转时间戳取最小值(推荐):

Math.min.apply(null, array.map(item => (new Date(item)).valueOf()));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...