C# Extension Method: Int16 - Milliseconds

CSharp · Console

/Program.cs

// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002370/int16-milliseconds

// @nuget: Z.ExtensionMethods

using System;
					
public class Program
{
	public static void Main()
	{
        Int16 [] values = { 1, 7, 30, 365, 1000, 2500, 10000, 15000, 32767 };

        Console.WriteLine("{0,21}{1,18}","Milliseconds", "TimeSpan");
        Console.WriteLine("{0,21}{1,18}","------------", "--------");

        foreach (Int16 value in values)
        {
			// C# Extension Method: Int16 - Milliseconds
            TimeSpan interval = value.Milliseconds();
            string timeInterval = interval.ToString();

            int pIndex = timeInterval.IndexOf(':');
            pIndex = timeInterval.IndexOf('.', pIndex);
            if (pIndex < 0) timeInterval += "        ";

            Console.WriteLine("{0,21}{1,26}", value, timeInterval);
        }
	}
}
;