Want To Display Server Utc Date Time Regardless Of Client Machines Datetime
I want to display the current date and time in UTC that the sever works with. How I can force javascript to work with the right date and time! I just want Javascript to show the ri
Solution 1:
This will give you the date in UTC
var now = newDate();
var now_utc = newDate(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
Solution 2:
If you want to use the datetime of the server while executing javascript on the client, the server will have to dynamically serve its time to the client, either as a separate http request or along with the web page that is calling the javascript.
Solution 3:
I have added one js file (date.js) in my aspx page. And write one function to display the date time.
<div id="clock">
</div>
functionUpdateUTCDateTime() {
var currentDate = Date.now();
var currentUTCdate = currentDate.toUTCString();
if (navigator.userAgent.indexOf("MSIE") < 0) {
currentUTCdate = currentUTCdate.replace("GMT", "UTC");
}
$("#Clock").text(Date.parseExact(currentUTCdate, "ddd, dd MMM yyyy HH:mm:ss UTC").toString("dd-MMM-yyyy hh:mm tt"));
setTimeout(UpdateUTCDateTime, (60 - currentDate.getSeconds()) * 1000);
}
So it will give me the Current UTC date time.
Post a Comment for "Want To Display Server Utc Date Time Regardless Of Client Machines Datetime"