加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 18:26:58 所属栏目:百科 来源:网络整理
导读:我使用这个代码将Timespan转换为String(例如:14:53): myTimeSpan.ToString("hh:mm"); 但是发生这个错误: Input string was not in a correct format 这样做的正确方法是什么? 解决方法 myTimeSpan.ToString(@"hh:mm") Custom TimeSpan Format Strings T
我使用这个代码将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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读