Skip to content

Instantly share code, notes, and snippets.

@mzuvin
Created May 7, 2020 15:07
Show Gist options
  • Save mzuvin/21fdfd5b0fa11fd16c4a5a16c90ab9cb to your computer and use it in GitHub Desktop.
Save mzuvin/21fdfd5b0fa11fd16c4a5a16c90ab9cb to your computer and use it in GitHub Desktop.
javascript addHours list range
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