Dec 21, 2009

How to get client date and time

You can use java script function to show the date and time.

<script type="text/javascript">
    function displayTime()
    {
        var localTime = new Date();
        var year= localTime.getYear();
        var month= localTime.getMonth() +1;
        var date = localTime.getDate();
        var hours = localTime .getHours();
        var minutes = localTime .getMinutes();
        var seconds = localTime .getSeconds();  
        var div=document.getElementById("div1");
        div.innerText=year+"-"+month+"-"+date+" "+hours+":"+minutes+":"+seconds;
    }
</script>



Then you can call it at web page.

<body onload="displayTime();">
    <form id="form2" runat="server">
    <div id="div1"></div>
    </form>
</body>

No comments:

Post a Comment