我正在制作一个应用程序来跟踪我的工作票,我对日期有疑问。我使用计时器从date2中减去date1但它不起作用。计时器计数以天为单位。
我想知道的是:为什么一分钟后天数变为0?
If ComboBox1.Text = "" Then
Else
Dim pItem As New ListViewItem
Timer1.Stop()
pItem.Text = ComboBox1.Text
pItem.SubItems.Add(Now.ToString)
pItem.SubItems.Add(Strings.Format(DateTimePicker1.Value))
pItem.SubItems.Add(DateDiff(DateInterval.Day, Now, CDate(DateTimePicker1.Text & " " & Now.TimeOfDay.ToString())).ToString & " Dias")
'& Now.Hour.ToString & "Horas" & Now.Minute.ToString & "Minutes")
ListView1.Items.Add(pItem)
ListView1.Refresh()
Timer1.Start()
End If
If Me.ListView1.Items.Count > 0 Then
For Each Item As ListViewItem In ListView1.Items
Dim TimeItem As String = Item.SubItems(2).Text
Dim DIfference As String = DateDiff(DateInterval.Second, Now, CDate(TimeItem)).ToString & " Days"
Next
End If
Me.ListView1.Refresh()
'CheckListView()
Public Sub CheckListView()
For Each item As ListViewItem In Me.ListView1.Items
If CDate(item.SubItems(2).Text) < Now Then 'Get the date of the item
Dim NewIt As New ListViewItem
NewIt.Text = item.Text
NewIt.SubItems.Add(item.SubItems(1).Text)
NewIt.SubItems.Add(item.SubItems(2).Text)
NewIt.SubItems.Add("To Delete")
Me.ListView1.Items.Add(NewIt)
ListView1.Items.RemoveAt(item.Index)
End If
Next
ListView1.Refresh()
答案 0 :(得分:0)
我无法获得计时器与它有什么关系,但是这里有一些代码可以用来获得你需要的东西。
Dim StartDate As Date = DateTimePicker1.Value
Dim CurrentDate As Date = Now
Dim mySpan As TimeSpan = CurrentDate.Subtract(StartDate)
Debug.Print($"Raw Span {mySpan}")
Debug.Print("TotalDays" & CInt(mySpan.TotalDays).ToString)
Debug.Print($"Days: {mySpan.Days}")
Debug.Print($"Hours: {mySpan.Hours}")