如何从字符串中读取?

Sne*_*rdd 0 c# methods datetime function datetimepicker

我正在尝试学习如何根据用户选择的时间来安排图片.

这是带有问题的代码:

private void startjob()
{
     string theDate = DateTimePicker1.Value.ToString();
     DateTime dt = Convert.ToDateTime(date);
     {
         DateTime start = new DateTime(2009, 12, 9, 10, 0, 0); //How Do I make this to read the string that is converted from DateTimePicker instead of this?
         DateTime end = new DateTime(2009, 12, 10, 12, 0, 0); //How Do I make this to read the string that is converted from DateTimePicker instead of this?
         DateTime now = DateTime.Now;
         if ((now > start) && (now < end))
         {
         //match found
         }
     }
}
Run Code Online (Sandbox Code Playgroud)

key*_*rdP 9

DateTimePicker.Value返回DateTime对象.您正试图不必要地转换为字符串类型.

DateTime start = DateTimePickerStart.Value;
DateTime end = DateTimePickerEnd.Value;
Run Code Online (Sandbox Code Playgroud)