c# 我想把一个动态的时间读出到TXT文件中,再窗体刷新后把TXT中的时间读出来该怎么实现?
stringtime1=DateTime.Now.ToString("HH:mm:ss");privatevoidtimer2_Tick(objectsender,Eve...
string time1 = DateTime.Now.ToString("HH:mm:ss");
private void timer2_Tick(object sender, EventArgs e)
{
string time2 = DateTime.Now.ToString("HH:mm:ss");
TimeSpan tt = TimeSpan.Parse(time1);
TimeSpan tt1 = TimeSpan.Parse(time2);
label9.Text = Convert.ToString(tt1.Subtract(tt));
} 展开
private void timer2_Tick(object sender, EventArgs e)
{
string time2 = DateTime.Now.ToString("HH:mm:ss");
TimeSpan tt = TimeSpan.Parse(time1);
TimeSpan tt1 = TimeSpan.Parse(time2);
label9.Text = Convert.ToString(tt1.Subtract(tt));
} 展开
1个回答
展开全部
DateTime time1 = DateTime.Now;
private void timer2_Tick(object sender, EventArgs e)
{
TimeSpan span = DateTime.Now - time1;
label9.Text = span.ToString("HH:mm:ss");
}
private void timer2_Tick(object sender, EventArgs e)
{
TimeSpan span = DateTime.Now - time1;
label9.Text = span.ToString("HH:mm:ss");
}
追问
呃~不是改格式,是要把label9读出到外面一个TXT文件中,而且time 是string格式的,还有用
追答
System.IO.File.AppendAllText(文件名, this.label9.Text + System.Environment.NewLine);
在你要写出数据的时候,执行这一句
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询