GTwoD
asked on
Deep Copy in Java script (Date)
Hi
how do I do a deep copy in JS, specifically with the date object.
E.g.
var now = new Date();
var tomorrow = now;// this does a shalow copy
var tomorrow.setDate( tomorrow.getDate+1);// this does will add a day to both refrences to the same date object :-(
My question is how would I do a deep copy of the now object and refer by tomorrow
regards
g2d
how do I do a deep copy in JS, specifically with the date object.
E.g.
var now = new Date();
var tomorrow = now;// this does a shalow copy
var tomorrow.setDate( tomorrow.getDate+1);// this does will add a day to both refrences to the same date object :-(
My question is how would I do a deep copy of the now object and refer by tomorrow
regards
g2d
now.getMilliseconds() ??
You mean now.getTime();
You mean now.getTime();
No now.getMilliseconds() is correct.
The constuctor of Date also accepts miliseconds. AFAIK Date constructot has 5 different contruct parameters-sets, one is Milliseconds.
The constuctor of Date also accepts miliseconds. AFAIK Date constructot has 5 different contruct parameters-sets, one is Milliseconds.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try it yourself
javascript:alert( new Date(new Date(1185449647512).getMil liseconds( )))
javascript:alert( new Date(new Date(1185449647512).getMil
ASKER
Thanks both,
Perhaps the working version should have been the accepted solution?
ASKER
sorry, mplungjan, you are right... I tohugt the othe version worked but it did not.
if you know a way I can retify this let me know.
g2d
if you know a way I can retify this let me know.
g2d
var now = new Date();
var tomorrow = new Date(now.getMilliseconds()
tomorrow.setDate( tomorrow.getDate()+1);