Nov 10, 2011

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>

Related posts:

1 comments:

I copied and paste but it is not working for me

Post a Comment

Your comments:

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More