I want to add one day or 12 hours to a date in the format of
Thu Mar 03 2022 12:00:00 GMT
I have tried:
new Date(value.startDate + 1);
but it does nothing.
Please help me out, I am new to JavaScript.
I want to add one day or 12 hours to a date in the format of
Thu Mar 03 2022 12:00:00 GMT
I have tried:
new Date(value.startDate + 1);
but it does nothing.
Please help me out, I am new to JavaScript.
Try this
const date = new Date("Thu Mar 03 2022 12:00:00 GMT");
date.setDate(date.getDate() + 1);
If you want to add something to your timestamp, this will do the trick no matter what you want to add.
const timestamp = new Date("Thu Mar 03 2022 12:00:00 GMT")
console.log(timestamp.toString())
// because getTime and setTime uses milliseconds:
const millisecondsToBeAdded = 12 * 60 * 60 * 1000
timestamp.setTime(timestamp.getTime() + millisecondsToBeAdded)
console.log(timestamp.toString())