javascript - Does cloning a date object in different timezone preserve it's original timezone? -
i have date object coming server in utc tz.
i want date arithmetics on client add days etc , sent server.
does doing like:
var newdate = new date(date); // cloning date in utc newdate.setdate(result.getdate() + 7); // expecting new date in utc
preserves original timezone ?
date objects not have timezones. of methods, getdate
(as opposed getutcdate
) or tostring
use local timezone calculate result return.
so answer question, yes, sample code preserves original timezone. sure that, when serializing send server, use toisostring()
(or tojson()
) instead of tostring()
.
Comments
Post a Comment