C# cs程序如何显示走动的时间 超简单哦啊 C# 时间随着服务器走动 我知道实现流程 就是显示不出来,不要说什么先获得服务器时间,根据时间差先加 我说的特简单 就是如何显示时间的走动用那个函数 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先获取服务器时间datetime serverDateTime = ;然后用定时器 Timer 控件 1000毫秒1次调用你写的获取时间的一个方法. 用 Timer 组件可以实现。先将Timer组件的Interval属性设置1000毫秒(即1秒)然后在Tick事件中写入 要获取的时间代码。 js 我的<script language="JavaScript" type="text/javascript"> function nowTime(format) { var dt = new Date(); //年份 this.Year = dt.getFullYear(); //月份 this.Month = dt.getMonth() + 1; //日期 this.Day = dt.getDate(); //星期几,数字 this.Week = dt.getDay(); //星期几,中文 this.WeekDay = '日一二三四五六'.charAt(dt.getDay()); //24制小时 this.Hours24 = dt.getHours(); //12制小时 this.Hours12 = this.Hours24 > 12 ? this.Hours24 - 12 : this.Hours24; //分钟 this.Minutes = dt.getMinutes(); //秒 this.Seconds = dt.getSeconds(); format = format.replace("yy", this.Year); format = format.replace("MM", this.Month); format = format.replace("dd", this.Day); format = format.replace("HH", this.Hours24); format = format.replace("hh", this.Hours12); format = format.replace("mm", this.Minutes); format = format.replace("ss", this.Seconds); format = format.replace("ww", this.Week); format = format.replace("WW", this.WeekDay); //时间显示在页面中哪个标签里,这里是其id this.toShow = function(element) { document.getElementById(element).innerHTML = format; } }</script>调用<script language="JavaScript" type="text/javascript" defer="defer"> setInterval("new nowTime('yy年MM月dd日 hh:mm:ss 星期WW').toShow('timeshow')", 1000);</script> 获取服务器时间到本地,然后用timer控件每个一秒加一次时间,就这么简单啊 千万不要每个一秒去获取服务器时间!那会造成服务器的负荷量会很大的!就在你页面初始化时获取一次时间,然后用timer控件每隔一秒像取到的时间加一秒。就这么简单 // 代码放在 Form_Load 事件里Timer timer = new Timer();timer.Interval = 10; // 1000ms = 1stimer.Tick += (obj, args) =>{ this.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ff");};timer.Start();this.FormClosed += (obj, args) =>{ timer.Stop(); timer.Dispose();}; private void button1_Click(object sender, EventArgs e){ System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer(); timer1.Tick += new EventHandler(timer1_Tick); timer1.Interval = 1000; timer1.Start();}void timer1_Tick(object sender, EventArgs e){ button1.Text = DateTime.Now.ToString();} 怎么在一个很大的数组中取第n个元素的值 sharepoint工作流中RollBackTask .Net关于分布式企业开发 请教各位老师,我用VS2005(C#)开发的WINFORM程序出现的自动转换成全角的问题 请教 如何在C#中 绘制 带颜色的字符串 xml xsd校验问题 怎样编程屏蔽网站弹出的要安装ActiveX插件的窗口? delphi+C#高手请进 打印预览高难度问题 求压缩算法 C#如何监测系统有无操作。 SnmpSharpNet walk问题,做过网管的进来看看 分不多,求高手指点如何获得网页弹出的confirm()框框?谢谢!
datetime serverDateTime = ;
然后用定时器
先将Timer组件的Interval属性设置1000毫秒(即1秒)
然后在Tick事件中写入 要获取的时间代码。
<script language="JavaScript" type="text/javascript">
function nowTime(format) {
var dt = new Date();
//年份
this.Year = dt.getFullYear();
//月份
this.Month = dt.getMonth() + 1;
//日期
this.Day = dt.getDate();
//星期几,数字
this.Week = dt.getDay();
//星期几,中文
this.WeekDay = '日一二三四五六'.charAt(dt.getDay());
//24制小时
this.Hours24 = dt.getHours();
//12制小时
this.Hours12 = this.Hours24 > 12 ? this.Hours24 - 12 : this.Hours24;
//分钟
this.Minutes = dt.getMinutes();
//秒
this.Seconds = dt.getSeconds();
format = format.replace("yy", this.Year);
format = format.replace("MM", this.Month);
format = format.replace("dd", this.Day);
format = format.replace("HH", this.Hours24);
format = format.replace("hh", this.Hours12);
format = format.replace("mm", this.Minutes);
format = format.replace("ss", this.Seconds);
format = format.replace("ww", this.Week);
format = format.replace("WW", this.WeekDay);
//时间显示在页面中哪个标签里,这里是其id
this.toShow = function(element) {
document.getElementById(element).innerHTML = format;
}
}
</script>调用<script language="JavaScript" type="text/javascript" defer="defer">
setInterval("new nowTime('yy年MM月dd日 hh:mm:ss 星期WW').toShow('timeshow')", 1000);
</script>
// 代码放在 Form_Load 事件里
Timer timer = new Timer();
timer.Interval = 10; // 1000ms = 1stimer.Tick += (obj, args) =>
{
this.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ff");
};timer.Start();this.FormClosed += (obj, args) =>
{
timer.Stop();
timer.Dispose();
};
{ System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Start();}
void timer1_Tick(object sender, EventArgs e)
{
button1.Text = DateTime.Now.ToString();
}