Skip to content

Instantly share code, notes, and snippets.

@msbrime
Created April 2, 2019 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msbrime/5b2ced276ad1479907f32eb18f0bc72a to your computer and use it in GitHub Desktop.
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
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