HWG*_*sey 3 c# wpf datetime timespan duration
我知道以前有人问过这个问题,但我不知道如何获得适用于我的特定示例的答案。这是一个用 C# 编写的 WPF 应用程序,我正在尝试从时间跨度中删除几分钟。
到目前为止,我已经让应用程序通过从完成时间中删除开始时间来计算持续时间,但我现在要做的是删除用户在表单中输入的分钟数。
这是到目前为止的代码
private void testcal_Click(object sender, EventArgs e)
{
string startTime = teststart.Text;
string finishTime = testfinish.Text;
// Trying to deduct this lunchTime var from the duration TimeSpan
string lunchTime = testlunch.Text;
TimeSpan duration = DateTime.Parse(finishTime).Subtract(DateTime.Parse(startTime));
testlabel.Text = duration.ToString(@"hh\:mm");
}
Run Code Online (Sandbox Code Playgroud)
编辑 - 更新为包括私人无效
您是在问如何从 TimeSpan 中减去分钟数吗?
如果是这样尝试像
TimeSpan ts = new TimeSpan().Subtract(TimeSpan.FromMinutes(30));
Run Code Online (Sandbox Code Playgroud)