var dateObj = new Date();
var val = dateObj.getTime();
//86400 * 1000 * 3 Each day is 86400 seconds
var days = 259200000;
val = val + days;
dateObj.setMilliseconds(val);
val = dateObj.getMonth() + 1 + "/" + dateObj.getDate() + "/" + dateObj.getFullYear();
alert(val);
I am trying to take the current date, add three days of milliseconds to it, and have the date stamp show 3 days later from the current. For example – if today is 10/09/2012 then I would like it to say 10/12/2012.
this method is not working, I am getting the months and days way off. Any suggestions?
To add time, get the current date then add, as milliseconds, the specific amount of time, then create a new date with the value:
To explain this further; the reason
dataObj.setMilliseconds()doesn’t work is because it sets the dateobj’s milliseconds PROPERTY to the specified value(a value between 0 and 999). It does not set, as milliseconds, the date of the object.References:
Date.now()new Date()Date.setMilliseconds()