格式时间跨度大于24小时 [英] Format TimeSpan greater than 24 hour
本文介绍了格式时间跨度大于24小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我将一些秒进TimeSpan对象是这样的:
Say I convert some seconds into the TimeSpan object like this:
Dim sec = 1254234568
Dim t As TimeSpan = TimeSpan.FromSeconds(sec)
我如何格式化的时间跨度对象变成像下面这样的格式:
How do I format the TimeSpan object into a format like the following:
>105hr 56mn 47sec
有一个内置的功能或者我需要写一个自定义函数?
Is there a built-in function or do I need to write a custom function?
推荐答案
那么,做最简单的事情是格式化这个自己,例如。
Well, the simplest thing to do is to format this yourself, e.g.
return string.Format("{0}hr {1}mn {2}sec",
(int) span.TotalHours,
span.Minutes,
span.Seconds);
在VB:
Public Shared Function FormatTimeSpan(span As TimeSpan) As String
Return String.Format("{0}hr {1}mn {2}sec", _
CInt(Math.Truncate(span.TotalHours)), _
span.Minutes, _
span.Seconds)
End Function
我不知道是否有任何的时间跨度
在.NET 4的格式将使这更简单。
I don't know whether any of the TimeSpan
formatting in .NET 4 would make this simpler.
这篇关于格式时间跨度大于24小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文