在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
前台页面代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>当期日期时间</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"> </asp:Timer> <asp:Label ID="lblTime" runat="server" Text=""></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html> 后台CS代码: using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Globalization; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } /// <summary> /// 事件发生改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Timer1_Tick(object sender, EventArgs e) { //第一种方法获取星期几 //string[] str1 = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" }; //string str2 = DateTime.Now.ToString("tt") == "上午" ? "AM" : "PM"; //lblTime.Text = "当前时间为:" + DateTime.Now.ToString("yyyy年MM月dd日") + " " + // str1[Convert.ToInt32(DateTime.Now.DayOfWeek)] + " " + DateTime.Now.ToLongTimeString()+; //第二种方法获取星期几 string str = DateTime.Now.ToString("tt") == "上午" ? "AM" : "PM"; lblTime.Text = "当前时间为:" + DateTime.Now.ToString("yyyy年MM月dd日") + " " + CultureInfo.GetCultureInfo("zh-cn").DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek) + " " + DateTime.Now.ToLongTimeString() + " " + str; } }
相关知识: <asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager> <asp:updatepanel ID="Updatepanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" Interval="1000" runat="server" ontick="Timer1_Tick" > </asp:Timer> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> <p></p> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" /> </Triggers> </asp:updatepanel> </div> <asp:Timer ID="Timer2" runat="server" Interval="3000" ontick="Timer2_Tick"> </asp:Timer>
推荐阅读: 这是用JS实现的。
|
请发表评论