繁体   English   中英

从dateTimePicker获取日期时间格式的时间?

[英]Getting time from dateTimePicker in date time format?

我在Visual Studio中工作,并且正在进行Outlook集成以添加新约会。

在软件内部,用户必须使用dateTime组件选择日期和时间(使用自定义格式显示时间)。

然后,我将此信息解析为以下Outlook代码:

Microsoft.Office.Interop.Outlook.Application outlookApp = 
  new Microsoft.Office.Interop.Outlook.Application(); 
Microsoft.Office.Interop.Outlook.AppointmentItem Appointment = 
   (Microsoft.Office.Interop.Outlook.AppointmentItem)
    outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem); 

Appointment.Subject = "Appraisal With " + tbFirstName.Text + " " + tbSurname.Text; 
Appointment.Body = "Appraisal with " + tbFirstName.Text + " " + tbSurname.Text + 
  "\n\n Details:\n-----------------------------------------\n First Name: " + 
  tbFirstName.Text + "\nSurname: " + tbSurname.Text + "\n Address: " + tbAddress.Text + 
  "\nDate & Time: " + dtpAppointment.ToString() + "\nContact Number: " + 
  tbPhoneNumber.Text + "\nEmail: " + tbEmail.Text;
Appointment.Location = tbAddress.Text; 
Appointment.ReminderSet = true; 
Appointment.ReminderMinutesBeforeStart = 120; 
Appointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; 
Appointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
Appointment.Save();

这样可以增加约会的原样,但是我需要在约会中添加日期和时间字段,对于我的一生,我无法弄清楚。

如果我使用此行:

Appointment.Start = dtpAppointment.Value;

我们认为日期还可以,但是时间始终是提交时计算机上的当前时间。 我需要约会的日期和约会的时间。

DateTimePicker的自定义格式是什么? 如果未显示时间,则“ Value将始终是所选日期和当前系统时间。

我想通了。

我将String推送到需要DateTime类型对象的字段中。 默认情况下,它由日期和时间组成,因此Outlook不知道在日期或时间部分将其放置在何处?

我只将时间转换为字符串。

string time = dtpAppointment.Value.ToString("HH:mm");

现在,日期和时间分开了,我仅将时间传递回了一个单独的DateTime对象。

DateTime timeConverted = Convert.ToDateTime(time);

然后,我两次指定Appointment.Start()参数一个作为日期,另一个作为时间,并将它们自动放入它们所属的部分中。

希望这对其他人有帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM