0

我存储了一个日期值并检索它,字符串中日期的格式是yyMMdd. 现在,当用户从字符串中加载它时,我想选择 DateTimePicker 作为用户加载日期。

示例代码:

string strDate = strRead.Substring(23, 6);
DateTime dt = DateTime.Parse(strDate);

谁能给我下一个想法?

4

3 回答 3

4

我猜最有效的方法是:

DateTimePicker p = new DateTimePicker();
DateTime result;
if (DateTime.TryParseExact("101025", "yyMMdd", CultureInfo.CurrentCulture, DateTimeStyles.None, out result))
{
    p.Value = result;
}
于 2010-10-25T08:26:55.347 回答
2

你的意思是

string strDate = strRead.Substring(23, 6);
DateTime dt = DateTime.Parse(strDate);
dateTimePicker.Value = dt;
于 2010-10-25T08:27:06.457 回答
1
dateTimePicker.Value = dt;
dateTimePicker.Focus(); //if by Select to meant to give it the focus
于 2010-10-25T08:28:12.630 回答