c# – 如何将TimeSpan转换为24小时和分钟字符串?

我使用这个代码将Timespan转换为String(例如:14:53):
myTimeSpan.ToString("hh:mm");

但是发生这个错误

Input string was not in a correct format

这样做的正确方法是什么?

解决方法

myTimeSpan.ToString(@"hh\:mm")

Custom TimeSpan Format Strings

The custom TimeSpan format specifiers do not include placeholder separator symbols,such as the symbols that separate days from hours,hours from minutes,or seconds from fractional seconds. Instead,these symbols must be included in the custom format string as string literals. For example,“dd.hh\:mm” defines a period (.) as the separator between days and hours,and a colon (:) as the separator between hours and minutes.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...