Datetimepicker用作datepicker [英] Datetimepicker use as a datepicker

查看:59
本文介绍了Datetimepicker用作datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用DateTimepicker,我想只选择日期部分。



我尝试了什么:



i像这样使用DateTimePicker.Value.Date



赞:目前正在进行:9/29/2011 12:00:00 AM



required:9/29/2011或09/29/2011。



我希望传递我的方法'09 / 29/2011'但传递去'9/29/2011 12:00: 00 AM





谢谢

Hi,
I am using DateTimepicker and i want to select only Date part.

What I have tried:

i using like this DateTimePicker.Value.Date

Like: currently comming : 9/29/2011 12:00:00 AM

required : 9/29/2011 or 09/29/2011.

and i want to pass in my method '09/29/2011' but Passing going '9/29/2011 12:00:00 AM


Thanks

推荐答案

快速解决方案是按空格分割日期并按下面给出的第一个拆分部分;



string date = DateTimePicker.Value.Date;

string newDate = date.Split('')[0];





现在newDate将包含你想要的东西;
A quick solution would be to split the date by space and take the first splitted part as given below;

string date = DateTimePicker.Value.Date;
string newDate = date.Split(' ')[0];


Now newDate will contain what you want;


根据需要对其进行格式化,参考自定义日期和时间格式字符串 [ ^ ]



Format it on your need, refer Custom Date and Time Format Strings[^]

string value = dateTimePicker1.Value.ToString("MM/dd/yyyy");


这篇关于Datetimepicker用作datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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