利用 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");
}

你可能感兴趣的:(timer,时间,实时更新)