TimeSpan to Localized String in C#

Posted by MadBoy on Stack Overflow See other posts from Stack Overflow or by MadBoy
Published on 2010-03-20T22:28:53Z Indexed on 2010/03/20 22:31 UTC
Read the original article Hit count: 579

Filed under:
|
|

Is there an easy way (maybe built in solution) to convert TimeSpan to localized string? For example new TimeSpan(3, 5, 0); would be converted to 3 hours, 5minutes (just in polish language).

I can of course create my own extension:

    public static string ConvertToReadable(this TimeSpan timeSpan) {
        int hours = timeSpan.Hours;
        int minutes = timeSpan.Minutes;
        int days = timeSpan.Days;
        if (days > 0) {
            return days + " dni " + hours + " godzin " + minutes + " minut";
        } else {
            return hours + " godzin " + minutes + " minut";
        }
    }

But this gets complicated if i want to have proper grammar involved.

© Stack Overflow or respective owner

Related posts about c#

Related posts about timespan