Backstage to get back the time, how to compare the size of time, I want to get the biggest time

the time taken back by the backstage, how to care about the size of the time, I want to get the largest time

clipboard.png

time(){
            let data=[
                {id:1,time:"2018-07-04 00:04:12"},
                {id:2,time:"2018-07-04 00:14:12"},
                {id:3,time:"2018-07-04 00:04:12"},
                {id:4,time:"2018-07-04 00:00:12"},
                {id:5,time:"2018-07-04 00:04:02"},
                {id:6,time:"2018-07-04 00:24:52"},
                {id:7,time:"2018-07-04 01:04:12"},
                {id:8,time:"2018-07-04 05:04:12"},
                {id:9,time:"2018-07-04 07:04:12"},
                {id:10,time:"2018-07-04 00:00:00"},
            ]
            for(var i=0;i<data.length;iPP){
                console.log(data[i].time);
                
            }
        }

how do I compare these times and get the maximum time?

Mar.23,2021

data.sort((a,b) => +new Date(a.time) < +new Date(b.time))[0]

see if this time can be converted into a timestamp. If not, it is best to have the backend send the timestamp to you directly.


    var time = new Date(Date.parse(sTime.replace(/-/g, "/")));

convert the format, compare the size directly, find the largest value, and return will be fine.

clipboard.png


compare with timestamp
it's best if the background can pass it over.
it's easy to turn it by yourself

const data = [
    { id: 1, time: "2018-07-04 00:04:12" },
    { id: 2, time: "2018-07-04 00:14:12" },
    { id: 3, time: "2018-07-04 00:04:12" },
    { id: 4, time: "2018-07-04 00:00:12" },
    { id: 5, time: "2018-07-04 00:04:02" },
    { id: 6, time: "2018-07-04 00:24:52" },
    { id: 7, time: "2018-07-04 01:04:12" },
    { id: 8, time: "2018-07-04 05:04:12" },
    { id: 9, time: "2018-07-04 07:04:12" },
    { id: 10, time: "2018-07-04 00:00:00" },
]

const max = data
    .reduce((max, m) => {
        return max.time > m.time ? max : m;
    });

console.log(max);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5a430-44dd5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5a430-44dd5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?