使用 c# 从时间跨度中删除秒 [英] remove seconds from timespan using c#
本文介绍了使用 c# 从时间跨度中删除秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 c# 从时间跨度中删除秒
I want to remove the seconds from timespan using c#
我的代码在这里:
TimeSpan lateaftertime = new TimeSpan();
lateaftertime = lateafter - Convert.ToDateTime(intime) ;
它返回值 00:10:00
但我想要下面的输出:00:10
不是秒字段 :00
.
But i want the below output :00:10
only not seconds field :00
.
推荐答案
好吧,你可以简单地做
Well you can simply do as
string.Format("{0}:{1}", ts.Hours,ts.Minutes) // it would display 2:5
编辑
正确格式化使用
string.Format("{0:00}:{1:00}", ts.Hours,ts.Minutes) // it should display 02:05
这篇关于使用 c# 从时间跨度中删除秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文