using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GluewaterProject
{
public partial class Form1 : Form
{
//记录本地初始运行的时间
DateTime BeginTime = DateTime.UtcNow;
public Form1()
{
InitializeComponent();
}
void Showtime()
{
string difftime = null;
//获得当前计算机的日期和时间,表示位协调通用时间
DateTime EndTime = DateTime.UtcNow;
//计算两个时间当量之间的运行差 函数为TimeSpan
TimeSpan Runtime = EndTime.Subtract(BeginTime).Duration();
TB_Runtime.Invoke(new ThreadStart(delegate()
{
//用对象选择需要显示的时间差,如:天,小时,分钟,秒
difftime = Runtime.Days.ToString() + "天"+
Runtime.Hours.ToString() + "小时" +
Runtime.Minutes.ToString() + "分钟" +
Runtime.Seconds.ToString() + "秒";
TB_Runtime.Text = difftime;
}));
}
private void CountTime_Tick(object sender, EventArgs e)
{
Showtime();
}
}
}