首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

VB.net 计算时间差,求,

2013-07-08 
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")
[解决办法]
引用:
找的如下帖子内容,这种效果就可以了:
    

        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分钟”
求帮忙~~~~


(DateDiff(DateInterval.Hour, time2, time1) Mod 24) & "小时" & (DateDiff(DateInterval.Minute, time2, time1) Mod 60) & "分钟"

热点排行