var k=new Date();
alert(k);
It alert local time. But I need to display current server UTC time.
JavaScript is basically on client side. You will not be able to get server time in java script as it will be executed on client and give you the server time only (Node.js is exception here).
If you really wish to have server time in javascript. You can write a Api or Webservice on serverside which will give you server time in format you want. Call this webservice/Api using XMLHTTP or Ajax request and parse the response and display the time as per your wish.
Ajax post Code Example :
$.post( "Your Web Service Page", function( data ) {
//Assuming that Your web service will not need any paramerter
and just write the server time in utc in response
alert(data );
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments