TimeSpan Seconds () là một phần của thời gian, trong khi TimeSpan TotalSeconds () chuyển đổi toàn bộ thời gian thành giây.
Đầu tiên chúng ta hãy xem phương thức TimeSpan Seconds ().
Ví dụ
using System;
using System.Linq;
public class Demo {
public static void Main() {
TimeSpan ts = new TimeSpan(0, 100, 0, 20, 0);
// seconds
Console.WriteLine(ts.Seconds);
}
} Đầu ra
20
Bây giờ, hãy để chúng tôi xem TotalSeconds hoạt động như thế nào cho cùng một giá trị TimeSpan.
Ví dụ
using System;
using System.Linq;
public class Demo {
public static void Main() {
TimeSpan ts = new TimeSpan(0, 100, 0, 20, 0);
// total seconds
Console.WriteLine(ts.TotalSeconds);
}
} Đầu ra
360020
Bây giờ, chúng ta sẽ thấy cả hai trong cùng một ví dụ.
Ví dụ
using System;
using System.Linq;
public class Demo {
public static void Main() {
TimeSpan ts = new TimeSpan(0, 100, 0, 20, 0);
// seconds
Console.WriteLine(ts.Seconds);
// total seconds
Console.WriteLine(ts.TotalSeconds);
}
} Đầu ra
20 360020