DWW,
I don't think that this is the best way to get the time portion as an
integer. The reason being that you would have to convert it back to a
string before you wanted to convert it into a time span again.
Rather, I would do this:
static int TimeSpanToInt32(TimeSpan timeSpan)
{
// Get the return value, rounded down.
return (int) Math.Floor(timeSpan.TotalSeconds);
}
To convert back, you do this.
static TimeSpan Int32ToTimeSpan(int timeSpan)
{
// Convert to a timespan.
return TimeSpan.FromSeconds(timeSpan);
}
Note that there will be some loss in the conversion here.
If you really want to just create an integer based on that string, it's
going to be a little harder, since you can't specify the format of the
timespan when calling ToString (and it expects a set format when it is
passed back as well).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"DWW" <al*@jsnospam.com> wrote in message
news:V9********************@giganews.com...
System.DateTime returns a string with the date and time. I want to
convert the time to an integer, for example, convert 10:24:45 to 102445.
Much research has turned up a myriad of variations on formatting using
Parse and DateTimeFormatInfo, but nothing that returns the time as an
integer. Any ideas?
Thanks.
DW