none
ASP.NET Web Forms FAQ: Bagaimana cara untuk mendapatkan tanggal dan waktu klien? RRS feed

  • Diskusi Umum

  • Anda dapat menggunakan fungsi java script untuk menampilkan tanggal dan waktu.

     

    <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>

     

    Kemudian Anda dapat memanggilnya di halaman web.

     

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

     Thread terkait: http://forums.asp.net/p/1247758/2303034.aspx


    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Jumat, 29 Juli 2011 03.07
    Moderator