vb.net每24小时之后的日期

vb.net date of the day after every 24 hours

我有一个计时器,它将每隔86400000秒(每24小时,因此每天)计时,以将新的日期放入DateTimePicker dtPicker1。不幸的是,在计时器滴答之后,结果带来了日期和日期(例如,2017-03-18 00:00:05,而不是2017-03-18)。当我使用消息框检查输出时,我得到的日期没有时间,但有第二天(计时器滴答之后,它会加上时间,因此代码失败。

`'每隔86400000毫秒(一天)进行滴答
dtPicker1.Enabled = True

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    dtPicker1.Text =""
    Dim mFmt As String ="yyyy-MM-dd"
    dtPicker1.Format = DateTimePickerFormat.Custom
    dtPicker1.CustomFormat = mFmt


    dtPicker1.Text =""

    Dim st As Date = Today.AddDays(-1).ToShortDateString

    Dim cf As String = Today.AddDays(-1)
    Dim dr As String = cf.Substring(3, 2)
    'MsgBox(dr)
    Dim de As String = cf.Substring(6, 4)
    Dim fg As String = cf.Substring(3, 2)
    Dim ab As String = cf.Substring(0, 2)

    'MsgBox(de &"-" & fg &"-" & ab, vbInformation,"Here you Go")

    dtPicker1.Value = de &"-" & fg &"-" & ab`

我们将不胜感激。


您不需要使用子字符串,可以将值直接设置为日期。

1
2
3
4
5
    dtPicker1.Text =""
    Dim mFmt As String ="yyyy-MM-dd"
    dtPicker1.Format = DateTimePickerFormat.Custom
    dtPicker1.CustomFormat = mFmt
    dtPicker1.Value = Today.AddDays(-1)