Seconds To String - CSharp System

CSharp examples for System:DateTime Second

Description

Seconds To String

Demo Code


using System.Globalization;
using System;/*from ww w.  ja va  2s  .c o  m*/

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

Related Tutorials