假设我有两个日期:
日期。现在:#8/10/2013 10:53:46 PM#
第二个日期是文件创建日期:
#7/10/2011 9:57:58 PM#
我想做类似的事情:Date.Now - FileDate
。
这是我的代码:
Dim ddd As TimeSpan = Date.Now - SecondDate
时间跨度中没有“年”属性。(年属性应该2
2013 - 2011 = 2
是,但有天属性 - 但我必须得到年/秒和月/秒)
更新:
谢谢大家,但我创建了一个函数:
Public Class Timee
Private _Days As Integer
Public Property Days() As Integer
Get
Return _Days
End Get
Set(ByVal value As Integer)
_Days = value
End Set
End Property
Private _Months As Integer
Public Property Months() As Integer
Get
Return _Months
End Get
Set(ByVal value As Integer)
_Months = value
End Set
End Property
Private _Years As Integer
Public Property Years() As Integer
Get
Return _Years
End Get
Set(ByVal value As Integer)
_Years = value
End Set
End Property
End Class
Public Function GetTimeBetween(ByVal datee As Date, ByVal datee2 As Date) As Timee
Dim tt As TimeSpan = datee - datee2
Dim dd11 As Integer = tt.Days
Dim bb1 As Integer
Dim Month As Integer
Dim Years1 As Integer
Do Until dd11 <= 0
bb1 = dd11
dd11 = dd11 - 365
Years1 = Years1 + 1
Loop
Years1 = Years1 - 1
Dim Dayss As Integer
Do Until bb1 <= 0
Dayss = bb1
bb1 = bb1 - 30
Month = Month + 1
Loop
Dim tt1 As New Timee
tt1.Days = Dayss
tt1.Months = Month
IF Years1 < 0 Then
Years1 = 0
End IF
tt1.Years = Years1
Return tt1
End Function
希望它对某人有所帮助。