Skip to content

Instantly share code, notes, and snippets.

@msbrime msbrime/add_time.js
Created Apr 2, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.