If you only want the server datetime when the page loads you could declare and initialise d
like this (inserting ASP into the JavaScript):
var d = new Date("<% =formatDateTime(now(),1) & " " & formatDateTime(now(),3) %>");
or, you if your server allows, you could declare a "jscript" script to run at the server which exposes a jscript function to ASP:
<script language="jscript" type="text/jscript" runat="server">
function getServerTime() { return new Date(); }
</script>
<script type="text/javascript">
var d = new Date("<% =getServerTime() %>");
</script>
If you want it to happen on an event like a button click then you could consider an ajax call to get the server datetime. Muhammed (above in the comments) has given an example and here's another : http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_suggest_asp.
The server side ASP code could just return the same as the above (<% =formatDateTime(now(),1) & " " & formatDateTime(now(),3) %>
)
I am assuming your users share the same timezone as the server and you won't have to do any timezone offset conversions.
I hope this helps. Best regards.
Here's my working:
<script language="jscript" type="text/jscript" runat="server">
function getServerTime() { return new Date(); }
</script>
<script type="text/javascript">
var d0 = new Date();
document.write("<br/><br/>Browser: " + d0);
var d1 = new Date("<% =formatDateTime(now(),1) & " " & formatDateTime(now(),3) %>");
document.write("<br/><br/>Server 1: " + d1);
var d2 = new Date("<% =getServerTime() %>");
document.write("<br/><br/>Server 2: " + d2);
</script>
<%
response.write "<br/><br/>Server in ASP 1: " & getServerTime()
response.write "<br/><br/>Server in ASP 2: " & now()
%>