为什么时间没有增加

Mas*_*ons -1 c# datetime winforms

我试图显示进程何时开始以及何时完成的时间戳,但我的时间从不增加(即使现实中的时间确实如此)

DateTime now = DateTime.Now;
txt1.AppendText(now + Environment.NewLine);
//Lengthy process that usually takes 2 - 3 minutes
txt1.AppendText(now);
Run Code Online (Sandbox Code Playgroud)

Phi*_*ton 5

您实际上使用的变量与第一次显示时的值相同.你需要像这样再次得到时间......

DateTime now = DateTime.Now;
txt1.AppendText(now + Environment.NewLine);
//Lengthy process that usually takes 2 - 3 minutes
DateTime timeHasPassed = DateTime.Now;
txt1.AppendText(timeHasPassed);
Run Code Online (Sandbox Code Playgroud)