如何用十进制转换日期?

时间:2016-01-13 09:59:47

标签: vb.net

如何以十进制转换DateTime?

这是我的代码不能正常工作

    Dim c = New DateTime(Now.Year, Now.Month, Now.Day, 9, 16, 0, 0)

    Dim d As Integer = (c.ToString("%h"))
    Dim duration As Decimal = 0



    Dim date1 As DateTime
    Dim date2 As DateTime

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

                    Else

                        date1 = CDate(read1("clog")).ToString("%h")
                        date2 = CDate(read1("cDlog")).ToString("%h")



                     Dim duration As Decimal = CDec(date2) - CDec(date1)

提前谢谢..

1 个答案:

答案 0 :(得分:1)

DateTime具有您可以使用的方法Subtract

Dim duration As System.TimeSpan
duration = date2.Subtract(date1)