I am into strange issue of javascript Date() function, these are the details
Server Side : Struts (ActionForm, Action class, jsp)
Client Side : jQuery, javascript
Now, I need a server time on the page and manipulate using javascript. So, I did Calendar.getInstance().getTimeinMillis(); in the action class and save it as an ActionForm attribute.
Now, at the client side, I got the long value (timeinMillis) from the styleId. But, to manipulate, when I do
var curTime = parseInt($("#serverTime").val());
var serverTime = new Date(curTime);
Now, the serverTime is providing client machine date and not server date though we are providing timeinMillis of server.
The strange part is when I pass string value of a date instead of long timeinMillis from server and pass it as an argument, it works well.
Any idea?
Finally resolved the issue with help of the above hints.
From java side, taken the offset from the UTC with the day light saving option.
so, in Action class
This gives the offset of local timezone and UTC timezone including day light saving
At the javascript, I used,
And, this gives correct server time with the day light saving options.
Thanks a lot for your help, without them, would not be possible to work it out. Cheers!