Hours To String - CSharp System

CSharp examples for System:DateTime Hour

Description

Hours To String

Demo Code


using System.Globalization;
using System;//from  w ww  .  ja  v  a 2  s . c  o  m

public class Main{
        public static string HoursToStr(int hours)
        {
            var mod = hours % 10;
            if (mod == 0 || hours > 10 && hours < 20)
                return hours + " hours ";
            if (mod == 1)
                return hours + " hour ";
            if (mod < 5)
                return hours + " hours ";
            return hours + " hours ";
        }
}

Related Tutorials