JSFiddle - React, Tailwind, and code Playground

by Yomi Eluwande

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>

JavaScript

// 1440 minutes make up a day
// which means there are 48 times in which we can can count 30 minutes
// you basically want to run a for loop 48 times to do the operation of creating 30 minutes time intervals

let timeArr = []
let theTime

// get the time in format of hour and minutes
  let today = moment().format('h:mm:ss');

for (let i = 0; i < 1440; i++ ) {
	// increase the no if minutes being added by 30 minutes, this will run for 48 times which is the equivalent of a day i.e 30 * 48 = 1440
	i += 30

	// add 30 minutes to the date
	theTime = moment(today, 'h:mm:ss a').add(i, 'minutes').format();
  //push into an array
  timeArr.push(moment(theTime).format('h:mm:ss')) 
  
 	console.log(theTime)
}
console.log(timeArr)