Matthew Ferri wrote on 23 jan 2005 in
microsoft.public.inetserver.asp.general:
I'm trying to display the server time on the local browser, just as
http://www.time.gov does it.
Is there any sample code for JS or VB available?
This gives running local time with server precision,
irrespective of the server local timezone:
[weekdays in Dutch and dd-mm-yyyy]
=======================================
<script runat=server language=javascript>
ds = new Date();
ds=ds*1;
</script>
<script type='text/javascript'>
ds= <% =ds %>; // UTC server
dc=new Date();
dc=dc*1; // UTC client
dif = ds-dc; // UTC difference
//alert(dif+' is the milliseconds UTC error between server and client')
function two(x){
return ((x<10)?"0":"")+x
}
var wkdgn=["zon","maan","dins","woens","donder","vrij","zater"]
function settijd(){
d = new Date()
d=new Date(d*1+dif);
document.getElementById('tijd').innerHTML=""+
wkdgn[d.getDay()]+"dag "+
two(d.getDate())+"-"+two(d.getMonth()+1)+"-"+d.getYear()+
"<br> <span style='font-size:22pt;font-weight:800;'>"+
two(d.getHours())+":"+two(d.getMinutes())+":"+
two(d.getSeconds())+"</span>"
setTimeout("settijd()",1000)
}
</script>
<body onload='settijd()'>
<div id='tijd'></div>
==================================