简体   繁体   中英

Time range using javascript or momentjs

Hi how to make Time range in 12-hour format using Javascript or MomentJS.

It need to be display from 12AM to 11:45PM. I need display every 15 min. Like this 12:00AM, 12:15AM, 12:30AM ect..

Here is image example how I need to display Time:

在此处输入图片说明

Using moment.js you can do this, which will give you exactly what you asked for:

 const start = moment().startOf('day'); const times = 24 * 4; // 24 hours * 15 mins in an hour for (let i = 0; i < times; i++) { const toPrint = moment(start) .add(15 * i, 'minutes') .format('hh:mm A'); console.log(toPrint); }
 <script src="https://unpkg.com/moment@2.24.0/moment.js"></script>

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