ASP.Net中的实际当前时间 [英] Current time on real basis in ASP.Net
本文介绍了ASP.Net中的实际当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我正在建立一个ASP.net网页,我想在实际的基础上显示当前时间。
我正在使用相同的计时器。
我的计时器代码是: -
Dear All,
I am building an ASP.net Webpage and I want to show the current time on real basis.
I am using a Timer for the same.
My code for timer is :-
<asp:ScriptManager ID = "ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID = "lblTime" runat="server" Font-Bold="True" Font-Names="Cambria" Font-Size="Small" ForeColor="Lime"></asp:Label>
</td>
</tr>
和计时器背后的代码是: -
and the code behind the timer is :-
protected void Timer1_Tick(object sender, EventArgs e)
{
lblTime.Text = "Current Time : " + System.DateTime.Now.ToShortTimeString();
}
当我尝试在Windows应用程序中执行相同的操作时,它的工作非常完美..
请帮我解决同样的问题..
谢谢。
When I try to do the same thing in an Windows Application, it works perfect..
Kindly help me with the solution for the same..
Thank you.
推荐答案
我找到了解决方案。
以下是相同的链接。
http://www.w3schools.com/js/tryit.asp?filename=tryjs_time [^] [ ^ ]
谢谢: - )
Hi,
I found the solution.
Below is the link for the same.
http://www.w3schools.com/js/tryit.asp?filename=tryjs_time[^][^]
Thanks :-)
You can use following code for this...
between <head>....</head> tag put
<% Response.AddHeader("Refresh", "timeinseconds") %> OR
<% Response.AddHeader("Refresh", "1") %>
and on page_load assign
lable.text = DateTime.Now().Tostring("TimeFormate");
Or You can also use Ajax Timer control for this.
这篇关于ASP.Net中的实际当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文