首先在窗体上拉个TextBox 然后在拉个timer 把timer的Enabled设置为true;
private void timer1_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now; //当前时间的实例;
textBox1.Text = dt.ToString(); //转为string类型 把值交给textBox1的Text属性;
}
C#显示时间代码如下:
using System.Diagnostics;
//在代码开始计时
Stopwatch sw = new Stopwatch(); //实例化一个对象
sw.Start(); //开始计算
//要执行的代码
//如果有多段需要计时,也可以用sw.Reset(); 再次初始化时间戳
//sw.Start(); 重新开始计时
sw.Stop(); //计算结束
sw.ElapsedMilliseconds就是耗费的时间,单位是毫秒。
要走得话得用JS写!!
如果在后台写得话,没一秒都要回发服务器,没一秒都不停得刷新。
首先在窗体上拉个TextBox 然后在拉个timer 把timer的Enabled设置为true;
private void timer1_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now; //当前时间的实例;
textBox1.Text = dt.ToString(); //转为string类型 把值交给textBox1的Text属性;
}
正解
Console.WriteLine(DateTime.Now.ToString());