时间跨度的ToString格式 [英] TimeSpan ToString format
本文介绍了时间跨度的ToString格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是好奇,是有格式字符串我可以用它来输出类似5H3米30年代?
如。 (显然是错误的)
myTimeSpan.ToString(HH毫米SS)
解决方案
尝试:
myTimeSpan.ToString(H'H'm'm的的')
(请注意,即使空间需要用引号括起来 - 这就是错了我的第一次尝试)
我假设你正在使用,当然.NET 4, - 在这之前,时间跨度
不支持自定义格式字符串
编辑:如前所述,这将无法工作超过24小时。还要注意的是替代品可通过野田的时间太:)
Just curious, is there a format string I can use to output something like "5h 3m 30s"?
eg. (obviously wrong)
myTimeSpan.ToString("hh mm ss")
解决方案
Try:
myTimeSpan.ToString("h'h 'm'm 's's'")
(Note that even spaces need to be quoted - that's what was wrong with my first attempt.)
I'm assuming you're using .NET 4, of course - before that, TimeSpan
didn't support custom format strings.
EDIT: As noted, this won't work beyond 24 hours. Also note that alternatives are available via Noda Time too :)
这篇关于时间跨度的ToString格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文