Các phương thức TimeSpan.From bao gồm FromDays, FromHours, FromMinutes, v.v.
Để lấy TimeSpan cho tất cả các phương pháp
// Days TimeSpan t1 = TimeSpan.FromDays(1); // Hours TimeSpan t2 = TimeSpan.FromHours(1); // Minutes TimeSpan t3 = TimeSpan.FromMinutes(1);
Sau đây là mã hoạt động trên tất cả các phương thức TimeSpan -
Ví dụ
using System;
using System.Linq;
public class Demo {
public static void Main() {
TimeSpan t1 = TimeSpan.FromDays(1);
TimeSpan t2 = TimeSpan.FromHours(1);
TimeSpan t3 = TimeSpan.FromMinutes(1);
Console.WriteLine(t1);
Console.WriteLine(t2);
Console.WriteLine(t3);
}
} Đầu ra
1.00:00:00 01:00:00 00:01:00