Home All Groups Group Topic Archive Search About
Author
21 Apr 2006 12:55 PM
Guido Kraus
Hi,

I'd like to convert a TimeSpan value to a String - but without seconds (e.g.
"12:01" for 12 hours and one minute). Is there a way to use String.Format()
or other functions to do this?

Thanks,
Guido

Author
21 Apr 2006 1:49 PM
Larry Lard
Guido Kraus wrote:
> Hi,
>
> I'd like to convert a TimeSpan value to a String - but without seconds (e.g.
> "12:01" for 12 hours and one minute). Is there a way to use String.Format()
> or other functions to do this?

You could convert to a DateTime and use that class's extensive
formatting available in ToString:

TimeSpan ts = new TimeSpan(12, 1, 14);
Console.WriteLine (ts.ToString());
DateTime dt = new DateTime(ts.Ticks);
Console.WriteLine (dt.ToString("hh:mm"));

output:
12:01:14
12:01

but maybe there is a cleaner way.

--
Larry Lard
replies to group please

AddThis Social Bookmark Button