由网友(滚床单嗎)分享简介:只是好奇,是有格式字符串我可以用它来输出类似5H3米30年代?如。 (显然是错误的)myTimeSpan.ToString(HH毫米SS)解决方案 尝试:myTimeSpan.ToString(H'H'm'm的的')(请注意,即使空间需要用引号括起来 - 这就是错了我的第一次尝试)我假设你正在使用,当然.NET 4,...
只是好奇,是有格式字符串我可以用它来输出类似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 :)
相关推荐
最新文章