C# cs程序如何显示走动的时间 超简单哦啊

昨日浮云 2011-01-21 01:00:56
C# 时间随着服务器走动 我知道实现流程 就是显示不出来,
不要说什么先获得服务器时间,根据时间差先加 我说的特简单 就是如何显示时间的走动
用那个函数
...全文
223 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2011-01-21
  • 打赏
  • 举报
回复
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();
}
yuanqingkun0103 2011-01-21
  • 打赏
  • 举报
回复
Timer();
龍过鸡年 2011-01-21
  • 打赏
  • 举报
回复

// 代码放在 Form_Load 事件里
Timer timer = new Timer();
timer.Interval = 10; // 1000ms = 1s

timer.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();
};
白鸽 2011-01-21
  • 打赏
  • 举报
回复
千万不要每个一秒去获取服务器时间!那会造成服务器的负荷量会很大的!就在你页面初始化时获取一次时间,然后用timer控件每隔一秒像取到的时间加一秒。就这么简单
白鸽 2011-01-21
  • 打赏
  • 举报
回复
获取服务器时间到本地,然后用timer控件每个一秒加一次时间,就这么简单啊
sunlongchina 2011-01-21
  • 打赏
  • 举报
回复
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>
t_j_c 2011-01-21
  • 打赏
  • 举报
回复
js也可以的
gohappy2008 2011-01-21
  • 打赏
  • 举报
回复
用 Timer 组件可以实现。
先将Timer组件的Interval属性设置1000毫秒(即1秒)
然后在Tick事件中写入 要获取的时间代码。
wy811007 2011-01-21
  • 打赏
  • 举报
回复
Timer 控件 1000毫秒1次调用你写的获取时间的一个方法.
freeboy827 2011-01-21
  • 打赏
  • 举报
回复
首先获取服务器时间
datetime serverDateTime = ;


然后用定时器
快溜 2011-01-21
  • 打赏
  • 举报
回复
Timer Tick事件 定时器

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧