我正在使用Telerik的RadDatePicker控件,我认为它本质上是一个DateTime控件,我想提取所选日期并将其字符串转换为变量。如果有人可以帮助我,那就太好了。
答案 0 :(得分:2)
:
DateTime? selectedDate = RadDatePicker1.SelectedDate;
//to string
string date="";
if(selectedDate!=null)
{
date=selectedDate.Value.ToShortDateString();//or selectedDate.Value.ToString("d");
}
else
{
//handle the case when user has not selected any date, and selectedDate is null
}
您可以在article in msdn之后格式化字符串表示。
答案 1 :(得分:0)
这就是我的所作所为:
string myDate = RadDatePicker1.SelectedDate.HasValue ?
RadDatePicker1.SelectedDate.Value.ToShortDateString() :
string.Empty;
答案 2 :(得分:0)
DateTime dt = Convert.ToDateTime(RadDatePicker1.SelectedDate); string temp = dt.ToShortDateString();
找到答案答案 3 :(得分:-1)
String.Format("{0:d}", RadDatePicker1.SelectedDate.ToString()); prints just date alone