用 DateTime dt = DateTime.Now 获取系统时间 只是取当前的时间 静态的显示
如何让秒,分,时…… 在控制台上是动态的显示 像电子手表上显示的时间那样
如何让秒,分,时…… 在控制台上是动态的显示 像电子手表上显示的时间那样
解决方案 »
- 如何得到填充的边境
- Json序列化存在外键的context对象失败,有好的解决办法没???
- WebBrowser怎么和HttpWebRequest共用WebBrowser的cookie?
- 很奇怪的问题: C#组件中引用了DirectX DLL, 造成调用它的C++项目调试时会自动中断!
- 不知道用哪个控件,还请指点
- 一个关于Spliter的问题,请大虾指点迷津
- 关于弹出窗体的问题
- 菜鸟请教一个小问题
- 用程序或脚本语言实现IIS网站的启动和关闭
- 今天早上我开了两个 STUDIO。NET 结果帮助不能用了,然后我关了一个,还是不能用,等我关第二个的时候提示出错,然后强行关了,重起后发
- select case语句查询数据
- 已有HttpWeb类 求代码注释及调用方法。没搞明白url和server的区别。如果我想在QQ群论坛里发贴子,要怎么调用。这个cookie是怎么取来的,怎么存放
document.write("<span id=labTime width='118px' height='11px' Font-Size='9pt'></span>") //输出显示日期的容器
//每1000毫秒(即1秒) 执行一次本段代码
setInterval("labTime.innerText=new Date().toLocaleString()",1000)
</script>
---------------------------复制到html里 就可以了。
{
DateTime dt = DateTime.Now;
label1.Text = dt.ToString();
} private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}搞个Timer,Interval设为1000,反正显示也是1秒一秒来的
{
this.label2.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
}
如果是webform 就要用ajax1秒去后台取一次
直接用js实现的 显示的是客户端的时间
然后双击你的timer控件,里面写this.label1.Text=DateTime.Now.ToString(),最后你双击你当前的窗体,在Form1_Load里再写一行this.label1.Text=DateTime.Now.ToString()!保证就OK了。
private void Form_Load(object sender, EventArgs e)
{
Timer time = new Timer();
time.Enabled = true;
time.Interval = 1000;
time.Tick += timerCD_Tick;
} private void timerCD_Tick(object sender, EventArgs e)
{
this.labInfor.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
using System;
using System.Text;
using System.Threading;
using System.Collections.Generic;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Thread ss = new Thread(timerCD_Tick);
ss.Start();
} private static void timerCD_Tick()
{
while (true)
{
Console.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Thread.Sleep(1000);
for (int i = 0; i < 19; i++)
{
Console.Write('\b');
}
}
}
}
}
要的就是这个 多谢仁兄了 楼上的timer也谢了 两种方法都学会了!
2、B/S 编码,页面加载首先后台获取,然后与前台的客户端时间比对时间差,然后使用js代码实现,比如这个函数 setInterval,步长设置为 1000毫秒
在控制台应用程序中添加System.Windows.Form引用。然后动态生成Timer。
using System.Text;
using System.Timers;
using System.Collections.Generic;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Timer myTimer = new Timer(1000);
myTimer.Elapsed += new ElapsedEventHandler(WriteTime);
myTimer.Start(); Console.ReadKey();
} static void WriteTime(object source, ElapsedEventArgs e)
{
for (int i = 0; i < 19; i++)
{
Console.Write('\b');
}
Console.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
}
{
this.label1.Text = DateTime.Now.ToString();
} private void timer1_Tick(object sender, EventArgs e)
{
this.label1.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); }
//timer1的属性设置 enabled=true,Interval=1000