C# 日期時間相減 (TimeSpan)

by on # C#
DateTime start = DateTime.Now;   
DateTime end = DateTime.Now;
//C#的日期型態可直接相減並傳回TimeSpan物件
TimeSpan ts = end - start;
 
//時間差換算成秒
String s1 = ts.TotalSeconds.ToString();
//時間差換算成分
String s2 = ts.TotalMinutes.ToString();
C#, TimeSpan
comments powered by Disqus