将没有日期值的昨天的日期获取到DateTimePicker中 [英] Get Yesterday's Date into DateTimePicker without time value

查看:94
本文介绍了将没有日期值的昨天的日期获取到DateTimePicker中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim cf As String = Today.AddDays(-1).ToString("yyyy-MM-dd")
        Dim dr As String = cf.Substring(3, 2)
       
        Dim de As String = cf.Substring(6, 4)
        Dim fg As String = cf.Substring(3, 2)
       Dim ab As String = cf.Substring(0, 2)
        dtPicker1.Value = de & "-" & fg & "-" & ab


Dim sd As Date = Today().AddDays(-1)
dtPicker1.Text = sd.Date.ToShortDateString
dtPicker1.Value = sd.ToShortDateString()

我想将昨天的日期放入没有时间的DateTimePicker dtPicker1中.上面显示的所有两个不同代码都加上了时间,并且dtPicker1的值变为 2017/04/04上午12:00:00. 同时,我只需要 2017年4月4日.帮助将不胜感激.


I want to get yesterday's date into a DateTimePicker, dtPicker1 without the time. All of the two different codes shown above add the time and the value of the dtPicker1 becomes 04/04/2017 12:00:00 AM . Meanwhile, I need just the 04/04/2017. Help will be greatly appreciated.


推荐答案

这只是显示问题吗?如果是这样,您应该只能够使用Format或Date函数格式化日期.如果您担心基础值,则Date数据类型(例如DateTimePicker.Value)将始终与时间部分相关联
Is this just a display issue? If so, you should just be able to format the date using Format or the Date functions. If you are concerned about the underlying value, a Date data type (e.g. DateTimePicker.Value) will always have a time portion associated with it.


这篇关于将没有日期值的昨天的日期获取到DateTimePicker中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆