小编HWG*_*sey的帖子

从时间跨度持续时间中删除分钟

我知道以前有人问过这个问题,但我不知道如何获得适用于我的特定示例的答案。这是一个用 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)

编辑 - 更新为包括私人无效

c# wpf datetime timespan duration

3
推荐指数
1
解决办法
3350
查看次数

标签 统计

c# ×1

datetime ×1

duration ×1

timespan ×1

wpf ×1