I am working on a small project where I am dealing with dates.
In order to get the today’s date, I’m currently using the following JavaScript code:
var today = new Date();
However, this results in the current date set on the client system, which may vary between systems, and hence the final output is different.
So in order to get the same result on all clients, I need to know the current date from the server. How can I get the server date in JavaScript?
Definitely getting server date is not possible without querying server.
So do a separate AJAX call to get the server date, or if your application already sends some ajax query, place the date in
Dateheader in server-side, and read it in client.Also if you entire page is served dynamically (like PHP), place server side date in html source like this: