利用 Timer 控件在頁面上顯示實時時間

<asp:ScriptManager ID="ScriptManager_Time" runat="server" />
<asp:UpdatePanel ID="UpdatePanel_Time" runat="server"> 
    <ContentTemplate> 
        <asp:Timer ID="SystemTime" runat="server" Interval="1000" OnTick="SystemTime_Tick"></asp:Timer> 
        <asp:Label ID="LabelTime" runat="server" Text="" ForeColor="#037A74" Font-Bold="true"></asp:Label>
    </ContentTemplate> 
</asp:UpdatePanel> 


protected void Page_Load(object sender, EventArgs e)
{
    LabelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}

protected void SystemTime_Tick(object sender, EventArgs e)
{
    LabelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章