简体   繁体   中英

how to display the data per hour in angular

How to display the data per hour?

for example:

data = [
    {
        'name' : 'sample'
        'date' : '2020-02-18 13:50:01'
    },
    {
        'name' : 'sample'
        'date' : '2020-02-18 13:20:01'
    },
    {
        'name' : 'sample'
        'date' : '2020-02-18 12:30:01'
    },
    {
        'name' : 'sample'
        'date' : '2020-02-18 11:50:01'
    },
    {
        'name' : 'sample'
        'date' : '2020-02-18 07:50:01'
    },
    {
        'name' : 'sample'
        'date' : '2020-02-18 01:50:01'
    }
]

what I want to do here is display the data from hour. example 14:00:00 - 13:00:00

const sample = data.filter((data) => { return data.date });

console.log(sample);

Live demo: https://runkit.com/embed/21avr87izvdn

在此处输入图片说明

    const data = [
    {
        'name' : 'sample',
        'date' : '2020-02-18 13:50:01'
    },
    {
        'name' : 'sample',
        'date' : '2020-02-18 13:20:01',
    },
    {
        'name' : 'sample',
        'date' : '2020-02-18 12:70:01'
    },
    {
        'name' : 'sample',
        'date' : '2020-02-18 11:50:01'
    },
    {
        'name' : 'sample',
        'date' : '2020-02-18 07:50:01'
    },
    {
        'name' : 'sample',
        'date' : '2020-02-18 01:50:01'
    }
];

const getTime = date => date.split(' ')[1]; 

const filterByRange = (start, end) => 
      data.filter(item =>  getTime(item.date) > start &&
                           getTime(item.date) < end);

filterByRange('13:00', '14:00');    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM