比較時間大小的實驗
string st
=
:
;
string st
=
:
;
DateTime dt
=Convert
ToDateTime(st
);
DateTime dt
=Convert
ToDateTime(st
);
DateTime dt
=DateTime
Now;
if(DateTime
Compare(dt
dt
)>
)
msg
Text=st
+
>
+st
;
else
msg
Text=st
+
<
+st
;
msg
Text+=
\r\n
+dt
ToString();
if(DateTime
Compare(dt
dt
)>
)
msg
Text+=
\r\n
+st
+
>
+dt
ToString();
else
msg
Text+=
\r\n
+st
+
<
+dt
ToString();
計算兩個時間差值的函數返回時間差的絕對值
private string DateDiff(DateTime DateTimeDateTime DateTime)
{
string dateDiff=null;
try
{
TimeSpan ts=new TimeSpan(DateTimeTicks);
TimeSpan ts=new TimeSpan(DateTimeTicks);
TimeSpan ts=tsSubtract(ts)Duration();
dateDiff=tsDaysToString()+天
+tsHoursToString()+小時
+tsMinutesToString()+分鐘
+tsSecondsToString()+秒;
}
catch
{
}
return dateDiff;
}
實現計算DateTime-天=DateTime的功能
TimeSpan ts=new TimeSpan();
DateTime dt=DateTimeNowSubtract(ts);
msgText=DateTimeNowToString()++tsDaysToString()+天\r\n;
msgText+=dtToString();
From:http://tw.wingwit.com/Article/program/net/201311/15292.html