C# 在 DatetimePicker 中只获取日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11929627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 19:45:05  来源:igfitidea点击:

get only Date in DatetimePicker

c#visual-studio-2010datetimedatetimepicker

提问by Rits

I am using Visual Studio 2010, I want to get only date as yyyy-MMM-ddformat in DateTimePicker. I tried :

我使用Visual Studio 2010,我想只有日期yyyy-MMM-dd的格式DateTimePicker。我试过 :

DateTime FromDate;
FromDate = 
 Convert.ToDateTime(DateTtimePickerFromDate.Value.Date.ToString("yyyy-MMM-dd"));

But it's not working.

但它不起作用。

回答by Jivan

dateTimePicker1 is a Control which displays the date and Time visually. This control help to select the date and time visually.You can get currently selected date or Time using

dateTimePicker1 是一个可视化显示日期和时间的控件。此控件有助于直观地选择日期和时间。您可以使用以下方法获取当前选择的日期或时间

dateTimePicker1.Value.ToShortDateString(); 

gets the Date in Short Format. Also in DateTime class, ToShortDateString() is possible. Ex.

获取短格式的日期。同样在 DateTime 类中,ToShortDateString() 也是可能的。前任。

DateTime dateTime = new DateTime();
    MessageBox.Show ( dateTime.ToShortDateString() );

回答by YATENDRA SHARMA

you can use this to save selected date time into database

您可以使用它来将选定的日期时间保存到 database

Convert.ToDateTime(dateTimePicker1.Text)