Charles,
IMHO Unfortunately it seems that TimeSpan is the "abandoned child" of the
Framework (a.k.a an omission or oversight of the Framework designers). In
that:
- TimeSpan does not implement IConvertible, nor does IConvertible support
TimeSpan (does not have a ToTimeSpan). Along with IConvertible there should
be a TypeCode.TimeSpan
- TimeSpan does not implement IFormattable & have custom formatting similar
to the "Time" part of DateTime.
If TimeSpan was IConvertible friendly then you could use Convert.ToString &
Convert.ToTimeSpan to convert Timespans to & from other types.
If TimeSpan was IFormattable friendly then it would support custom
formatting.
--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
| Hi Jay
|
| Thanks for the reply. As I feared it is not a one-liner. With all the
other
| formatting options, is this an omission, in your view, that TimeSpan does
| not have ToString that can take a format?
|
| Charles
|
|
| message | > Charles,
| > What I normally do when I need custom formatting of a TimeSpan is
| > "convert"
| > it to a DateTime, then use custom DateTime formatting. Something like:
| >
| > Dim ts As TimeSpan
| > Dim dt As DateTime = DateTime.MinValue.Add(ts)
| > Dim s As String
| >
| > s = ts.ToString() ' default TimeSpan formatting
| > s = dt.ToString("H:mm:ss") ' custom DateTime formatting
| >
| >
| > For details on custom datetime formats see:
| >
| >
http://msdn.microsoft.com/library/d...s/cpguide/html/cpcondatetimeformatstrings.asp
| >
| > For information on formatting in .NET in general see:
| >
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp
| >
| > --
| > Jay [MVP - Outlook]
| > .NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley -
http://www.tsbradley.net
| >
| >
| > | > | If I display a TimeSpan I get something like
| > |
| > | 00:05:17.6217891
| > |
| > | when what I would like to see is
| > |
| > | 00:05:18
| > |
| > | Is there an easy way to get this output? Try as I might I just can't
| > find
| > | it.
| > |
| > | TIA
| > |
| > | Charles
| > |
| > |
| >
| >
|
|