M
M
mrzgt2018-01-31 20:33:38
JavaScript
mrzgt, 2018-01-31 20:33:38

How to add one day to a date?

Tell me why it works and adds 1 day,
var timeend2 = new Date(2018,01,31);
alert(timeend2);
timeend2.setDate(timeend2.getDate() +1);
but alert shows
Sat Mar 03 2018 00:00:00 GMT+0200
var timeend2 = new Date();
timeend2.setDate(timeend2.getDate() +1);
if so, then 1 day does not add

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2018-01-31
@petermzg

var secoffs =  24 * 60 * 60 * 1000;
var vof = timeend2.valueOf();
var i = 1; // one day
var newdate = new Date(vof + (secoffs * i));

W
webe, 2018-01-31
@webe

moment.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question