格式化时间跨度 [英] Formatting TimeSpans

查看:164
本文介绍了格式化时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图格式化时间跨度通过下面的代码行:



的ToString(并[d] HH:MM:SS)



它抛出一个 FormatException ,但异常消失,当我删除 [] 。我也不能包含空格。有谁知道为什么发生这种情况?在这个 MSDN页面它明确规定您可以包含这些字符。我使用.NET Framework 4.5.2 BTW。



感谢。


解决方案

 时间跨度TS =新的TimeSpan(5,10,44); 
字符串测试=的String.Format({0:dd\\:hh\\:mm\\:ss\\.ffff},TS);


I am trying to format a TimeSpan with the following line of code:

.ToString("[d.]hh:mm:ss")

It throws a FormatException, but the exception goes away when I remove the :, the [], and the .. I also cannot include spaces. Does anyone know why this is happening? On this msdn page it clearly states that you can include these characters. I am using .Net framework 4.5.2 btw.

Thanks.

解决方案

TimeSpan ts = new TimeSpan(5, 10, 44);
string test = string.Format("{0:dd\\:hh\\:mm\\:ss\\.ffff}", ts);

这篇关于格式化时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆