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.TimeSp an
- 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.ToStrin g &
Convert.ToTimeS pan 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
"Charles Law" <bl***@nowhere. com> wrote in message
news:ej******** ******@TK2MSFTN GP10.phx.gbl...
| 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
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> wrote in
| message news:e7******** ******@TK2MSFTN GP14.phx.gbl...
| > 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.MinVal ue.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/de...matstrings.asp
| >
| > For information on formatting in .NET in general see:
| >
http://msdn.microsoft.com/library/de...ttingtypes.asp
| >
| > --
| > Jay [MVP - Outlook]
| > .NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley -
http://www.tsbradley.net
| >
| >
| > "Charles Law" <bl***@nowhere. com> wrote in message
| > news:ef******** ******@TK2MSFTN GP15.phx.gbl...
| > | If I display a TimeSpan I get something like
| > |
| > | 00:05:17.621789 1
| > |
| > | 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
| > |
| > |
| >
| >
|
|