我有一个计时器,在每个 86400000秒(每24小时,因此每天)之后打勾,将新的一天放在DateTimePicker中, dtPicker1 。不幸的是,在计时器打勾后,结果会带来除日期之外的一天中的时间(例如 2017-03-18 00:00:05 ,而不是 2017-03-18 。当我使用消息框检查输出时,我得到的日期没有时间,但第二天(在计时器滴答之后,它会增加时间,因此代码失败。
`'每86400000毫秒(一天)滴答 dtPicker1.Enabled = True
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`
非常感谢帮助。
答案 0 :(得分:1)
您不需要使用子字符串,您可以将值直接设置为日期。
dtPicker1.Text = ""
Dim mFmt As String = "yyyy-MM-dd"
dtPicker1.Format = DateTimePickerFormat.Custom
dtPicker1.CustomFormat = mFmt
dtPicker1.Value = Today.AddDays(-1)