如何将时间跨度转换为格式化字符串?

编程入门 行业动态 更新时间:2024-10-24 13:25:42
本文介绍了如何将时间跨度转换为格式化字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述   

可能重复:结果  How我可以用的String.format自定义格式的TimeSpan对象在.NET?

精确副本  

时间跨度格式

在这里第一个问题:

我有两个日期时间增值经销商,BEGINTIME和结束时间。我已经通过执行以下操作得到他们的区别是:

时间跨度dateDifference = endTime.Subtract(BEGINTIME);

如何我现在可以使用C#返回这个字符串HH小时,毫米分钟,SS秒格式。

如果差异00:06:32.4458750

这应该返回这00小时,06分钟,32秒

感谢您的帮助。

解决方案

TimeSpan.ToString()做的伎俩适合你?如果不是,它看起来像页面上的code样本描述了如何做一个时间跨度对象的自定义格式。

Possible Duplicate: How can I String.Format a TimeSpan object with a custom format in .NET?

Exact Duplicate

Timespan formatting

First question here:

I have two DateTime vars, beginTime and endTime. I have gotten the difference of them by doing the following:

TimeSpan dateDifference = endTime.Subtract(beginTime);

How can I now return a string of this in hh hrs, mm mins, ss secs format using C#.

If the difference was 00:06:32.4458750

It should return this 00 hrs, 06 mins, 32 secs

Thanks for the help

解决方案

Would TimeSpan.ToString() do the trick for you? If not, it looks like the code sample on that page describes how to do custom formatting of a TimeSpan object.

更多推荐

如何将时间跨度转换为格式化字符串?

本文发布于:2023-11-16 17:05:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跨度   字符串   转换为   如何将   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!