C#의 TimeSpan.FromMinutes() 메서드는 지정된 시간(분)을 나타내는 TimeSpan을 반환하는 데 사용되며 사양은 밀리초 단위까지 정확합니다.
구문
public static TimeSpan FromMinutes (double val);
위에서 val 값은 분 단위로 가장 가까운 밀리초 단위로 정확합니다.
예시
using System; public class Demo { public static void Main() { TimeSpan span1 = TimeSpan.FromHours(0.78787); TimeSpan span2 = new TimeSpan(10, 30, 40); TimeSpan span3 = TimeSpan.FromHours(5); TimeSpan span4 = TimeSpan.FromMilliseconds(1); TimeSpan span5 = TimeSpan.FromMinutes(100); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("TimeSpan4 = "+span4); Console.WriteLine("TimeSpan5 = "+span5); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); Console.WriteLine("Result (Comparison of span2 and span3) = "+TimeSpan.Compare(span2, span3)); Console.WriteLine("Result (Comparison of span1 and span3) = "+TimeSpan.Compare(span1, span3)); Console.WriteLine("Result (Comparison of span3 and span4) = "+TimeSpan.Compare(span3, span4)); Console.WriteLine("Result (Comparison of span4 and span5) = "+TimeSpan.Compare(span4, span5)); } }
출력
TimeSpan1 = 00:47:16.3320000 TimeSpan2 = 10:30:40 TimeSpan3 = 05:00:00 TimeSpan4 = 00:00:00.0010000 TimeSpan5 = 01:40:00 Result (Comparison of span1 and span2) = -1 Result (Comparison of span2 and span3) = 1 Result (Comparison of span1 and span3) = -1 Result (Comparison of span3 and span4) = 1 Result (Comparison of span4 and span5) = -1
예시
using System; public class Demo { public static void Main() { TimeSpan span1 = TimeSpan.FromMinutes(200); TimeSpan span2 = new TimeSpan(20, 10, 15); TimeSpan span3 = TimeSpan.FromHours(.78); TimeSpan span4 = TimeSpan.FromMilliseconds(1); TimeSpan span5 = TimeSpan.FromMinutes(150); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("TimeSpan4 = "+span4); Console.WriteLine("TimeSpan5 = "+span5); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); Console.WriteLine("Result (Comparison of span2 and span3) = "+TimeSpan.Compare(span2, span3)); Console.WriteLine("Result (Comparison of span1 and span3) = "+TimeSpan.Compare(span1, span3)); Console.WriteLine("Result (Comparison of span3 and span4) = "+TimeSpan.Compare(span3, span4)); Console.WriteLine("Result (Comparison of span4 and span5) = "+TimeSpan.Compare(span4, span5)); } }
출력
TimeSpan1 = 03:20:00 TimeSpan2 = 20:10:15 TimeSpan3 = 00:46:48 TimeSpan4 = 00:00:00.0010000 TimeSpan5 = 02:30:00 Result (Comparison of span1 and span2) = -1 Result (Comparison of span2 and span3) = 1 Result (Comparison of span1 and span3) = 1 Result (Comparison of span3 and span4) = 1 Result (Comparison of span4 and span5) = -1