Created
May 7, 2020 15:07
-
-
Save mzuvin/21fdfd5b0fa11fd16c4a5a16c90ab9cb to your computer and use it in GitHub Desktop.
javascript addHours list range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date.prototype.addHours = function(h) { | |
this.setTime(this.getTime() + (h * 60 * 60 * 1000)); | |
return this; | |
} | |
var startDate = new Date('Sun Apr 19 2020 07:00:00 GMT+0300 (GMT+03:00)'); | |
var finishDate = new Date('Sun Apr 19 2020 10:00:00 GMT+0300 (GMT+03:00)'); | |
checkedList = [] | |
while (startDate < finishDate) { | |
var sTime = startDate.toLocaleTimeString('tr-TR'); | |
startDate.addHours(1) | |
var fTime = startDate.toLocaleTimeString('tr-TR'); | |
checkedList.push(`${sTime}-${fTime}`) | |
} | |
console.log(checkedList) | |
//(3) ["07:00:00-08:00:00", "08:00:00-09:00:00", "09:00:00-10:00:00"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment