VB.net 计算时间差,急求,在线等~找的如下帖子内容,这种效果就可以了:Dim time1 As Date NowDim time2 As
VB.net 计算时间差,急求,在线等~ 找的如下帖子内容,这种效果就可以了:
Dim time1 As Date = Now Dim time2 As Date = "2003-2-4" MsgBox(CInt((DateDiff(DateInterval.Day, time2, time1)) / 365) & "年" & CInt(((DateDiff(DateInterval.Day, time2, time1)) Mod 365) / 30) & "月" & CInt(((DateDiff(DateInterval.Day, time2, time1)) Mod 365) Mod 30) & "日")
想模仿它计算时间差:
Dim time1 As Date = CDate(Format(Now(), "HH:mm")) Dim time2 As Date = CDate("14:30") TextBox1.Text = CInt((DateDiff(DateInterval.Hour, time2, time1)) / 24) & "小时" & CInt(((DateDiff(DateInterval.Minute, time2, time1)) Mod 24) / 60) & "分钟"
实现的结果却是“0小时0分钟” 求帮忙~~~~ [解决办法] 建议你看看TimeSpan类 [解决办法] new TimeSpan(dt1.Tick, dt2.Tick).ToString("hh:mm") [解决办法]
(DateDiff(DateInterval.Hour, time2, time1) Mod 24) & "小时" & (DateDiff(DateInterval.Minute, time2, time1) Mod 60) & "分钟"