Friendly TimeSpan Duration - CSharp System

CSharp examples for System:TimeSpan

Description

Friendly TimeSpan Duration

Demo Code


using System.Text;
using System.Collections.Generic;
using System;//from   www . ja  va 2 s  .c  o m

public class Main{
        public static string FriendlyDuration(this TimeSpan time)
        {
            if (time.TotalSeconds < 1) return "less than a second";
            if (time.TotalMinutes < 1) return Format(time.TotalSeconds, "second");
            if (time.TotalHours < 1) return Format(time.TotalMinutes, "minute");
            if (time.TotalDays < 1) return Format(time.TotalHours, "hour");
            return Format(time.TotalDays, "day");
        }
}

Related Tutorials