Wednesday, 14 March 2018

Simplest way to display Server Time in JSP using js

THE BELOW CODE WORKS ONLY IN JSP :

<html>
<body >
<table width="95%" border="1" cellpadding="1" cellspacing="1" style="margin-left:2; margin-top:10;margin-bottom:10;">
<tr>
<td><strong>Server Time&nbsp;:&nbsp;&nbsp;</strong><label id="timelable"></label></td>
</tr>
<tr>
<td><strong>Client Time&nbsp;:&nbsp;&nbsp;</strong><label id="timeClient"></label></td>
</tr>
</table>
</body>
<script type="text/javascript">
var myVar = setInterval(function(){ myTimer() }, 1000);
var jsVar=  <%=java.util.Calendar.getInstance().getTimeInMillis()%>;
var k = new Date(jsVar);
var timeZoneOffset=<%=java.util.TimeZone.getDefault().getOffset(System.currentTimeMillis())%>;
jsVar=jsVar+timeZoneOffset;

function myTimer() {
jsVar=jsVar+1000;
var d = new Date(jsVar);
var t=d.toUTCString();
document.getElementById("timelable").innerHTML = t;
document.getElementById("timeClient").innerHTML=k;
}
</html>

Simplest way to display Server Time in JSP using js

THE BELOW CODE WORKS ONLY IN JSP : <html> <body > <table width="95%" border="1" cellpadding="1...