且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从格式“hh:mm:ss"转换 TimeSpan到“hh:mm"

更新时间:2022-06-13 15:42:59

你需要将你的数据转换成TimeSpan,然后使用格式:"hh:mm"

You need to convert your data to TimeSpan and then use format:"hh:mm"

string test ="08:00:00";
TimeSpan ts = TimeSpan.Parse(test);
Console.Write(ts.ToString(@"hh:mm"));

在你的情况下:

var test = dataRow.Field<TimeSpan>("fstart").ToString(@"hh:mm"));

记得转义冒号:

您可能会看到:自定义时间跨度格式字符串