I made a function which displays date on the webpage,, and i uploaded the same onto some server…
But when i changed the date of my system, i noticed that the date is dependent on client machine..
Is it not possible to get the date from actual time server and embed that code into my program..
Hope i am able to explain my doubt.. Please give some solution to this with small sample code..that would be helpful..
Thanks a lot..
If you have written it in javascript, well…that always executes on the client side. If you are calculating date through javascript, its too late, that code is gone.
To solve this, you would have to make your js function receive data through parameters, and that data should be calculated on the server side.
You could do something like.
Or more elegantly, get server date in your java class, and write it to request:
And then, in your jsp, using for example, JSTL
Or,
EDIT: In response to your comment, you should:
I have no idea what your time zone is, but I’m sure you do.
Calendar.getInstance() takes an instance of TimeZone as a parameter. That should do it
Take a look:
http://java.sun.com/javase/6/docs/api/java/util/TimeZone.html
http://java.sun.com/javase/6/docs/api/java/util/Calendar.html
Interesting link about JSP