简体   繁体   English

从 TimeSpan Duration() 中删除秒数

[英]Remove Seconds from TimeSpan Duration()

I want to remove only the seconds part of the output which comes as my ActualWorkedHours variable [HH:mm:ss].我只想删除作为我的ActualWorkedHours变量 [HH:mm:ss] 的输出的秒部分。

This is my C# code:这是我的 C# 代码:

    ActualWorkedHours =(shiftAttendanceBo.ActOutDateTime.Value.Subtract(shiftAttendanceBo.ActInDateTime.Value).Duration().ToString()

How can I do this?我怎样才能做到这一点?

如果您使用 .Net 4,则可以使用ToString(@"hh\\:mm")

TimeSpan ts = (shiftAttendanceBo.ActOutDateTime.Value.Subtract(shiftAttendanceBo.ActInDateTime.Value).Duration()
ActualWorkedHours = (ts - new TimeSpan(0, 0, ts.Seconds)).ToString();
    TimeSpan ts = new TimeSpan(10,30,15);
    Console.WriteLine(ts.ToString(@"hh\:mm"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM