我在C#中创建了以下功能,以便在Outlook中创建约会。每件事情都运作正常但是当我试图在2014年4月8日(dd / MM / YYYY)设定任命时,预约将于2014年8月4日在Outlook中设定。
我尝试过投标DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm", null)
,但它不起作用。
public void OutLookReminder(string DateTimeVal)
{
Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment
oAppointment.Subject = "........Subject"; // set the subject
oAppointment.Body = "--------Body"; // set the body
oAppointment.Location = "-------Location"; // set the location
oAppointment.Start = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm",null); // Set the start date
oAppointment.End = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm", null); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
// save the appointment
oAppointment.Save();
}
答案 0 :(得分:1)
您在DateTime.ParseExact(,"Formate!!!",)
中指定的解析格式是识别日期字段和年份和月等....然后将其存储到日期时间变量.....
我认为你的文化是"MM/dd/yyyy"
尝试以这种格式解析
答案:
DateTime t1=DateTime.ParseExact(DateTimeVal, "MM/dd/yyyy H:mm",null);
这将给你你想要的......
请注意,如果你再次解析这个格式化的字段,答案将根据你的文化......