Skip to content
Advertisement

Javasript check current datetime with loop 2 between datetimes

I’m working with time loop.

JavaScript

Now I have this FlipClock plugin,

JavaScript

My question, is it possible to check if there is a currentTime between startShow and endShow match with my above code?

Advertisement

Answer

Instead of two arrays for startShow and endShow, take one array as showTime and add object with startShow and endShow value. Also do not format time as it will convert value to string. Instead left it as moment object.

Similarly inside interval: function() get currentTime with var currentTime = moment(moment(new Date()).format('MM/DD/YYYY ') + time); only. Now your condition will be like showTime.some(s => s.startShow <= currentTime && s.endShow >= currentTime) which will return true if currentTime is between any startShow & endShow from any showTime array.

JavaScript

Try it at below.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement