在vb.net中减去时间

时间:2016-07-20 04:25:59

标签: vb.net ms-access-2010

大家好我需要帮助来减去时间。 7:31:52 AM - 4:30:32输出 3小时1分20秒

Dim date1 = New DateTime(Now.Year, Now.Month, Now.Day, 7, 30, 0, 0)
Dim date2 = DateTime.Parse("4:30:00 PM")

If read1("clog") Is (DBNull.Value) Then

Else
    date1 = read1("clog")
    Dim duration As Double = (date2 - date1).Minutes

    Label4.Text = duration
End If

1 个答案:

答案 0 :(得分:1)

Dim time1 As DateTime = #7/20/2016 7:31:52 AM#
        Dim time2 As DateTime = #7/20/2016 4:30:00 PM#
        Dim ts As TimeSpan = time2 - time1
        MsgBox(ts.Days & " day(s) " & ts.Hours & " hour(s) " & _
               ts.Minutes & " minute(s) " & ts.Seconds & " second(s)")


Dim date1 As DateTime


                    Dim date2 = DateTime.Parse("4:30:00 PM")

                    If read1("clog") Is (DBNull.Value) Then

                    Else

                        date1 = read1("clog")
                        Dim duration As TimeSpan = date2 - date1

                        Label4.Text = String.Format("{0} hour(s) {1} minute(S) {2} second(s)", duration.Hours, duration.Minutes, duration.Seconds

                    End If