如何将时间跨度转换为格式化字符串? [英] How do I convert a TimeSpan to a formatted string?

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

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/574881/how-can-i-string-format-a-timespan-object-with-a-custom-format-in-net\">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.

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

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