Created
April 2, 2019 09:14
-
-
Save msbrime/5b2ced276ad1479907f32eb18f0bc72a to your computer and use it in GitHub Desktop.
Add days to a date in javascript. Can use in conjunction with `setHours` to get the exact time of a specific day
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
function addDaysToDate(date,numberOfDays){ | |
return new Date( | |
date.getTime() + | |
daysToMilliseconds(numberOfDays) | |
); | |
} | |
function daysToMilliseconds(days){ | |
return days * 86400000 | |
} | |
console.log(addDaysToDate(new Date(),6).toDateString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment