C# 更改Outlook约会日期格式
我在C#中创建了以下函数,用于在Outlook中创建约会。一切都很顺利,但当我试图在2014年4月8日(dd/MM/YYYY)设定约会时,Outlook在2014年8月4日设定了约会 我曾尝试强制转换为C# 更改Outlook约会日期格式,c#,.net,outlook,C#,.net,Outlook,我在C#中创建了以下函数,用于在Outlook中创建约会。一切都很顺利,但当我试图在2014年4月8日(dd/MM/YYYY)设定约会时,Outlook在2014年8月4日设定了约会 我曾尝试强制转换为DateTime.ParseExact(DateTimeVal,“dd/MM/yyyy H:MM”,null),但它不起作用 public void OutLookReminder(string DateTimeVal) { Outlook.Application outlookApp =
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();
}
解析您在
DateTime中指定的格式。ParseExact(,“Formate!!!”,)
用于标识日期字段以及年和月等。。。。然后将其存储到datetime变量中
我认为您的文化是“MM/dd/yyyy”
尝试以这种格式进行分析
答复:
DateTime t1=DateTime.ParseExact(DateTimeVal, "MM/dd/yyyy H:mm",null);
这会给你你想要的
请注意,如果您再次解析此格式化字段,答案将根据您的文化…我刚才尝试了您提到的方法,但遗憾的是结果是相同的。DateTime TimeSchedule=DateTime.ParseExact(DateTimeVal,“dd/MM/yyyyy H:MM”,null);格式化的字符串_date=TimeSchedule.ToString(“dd/MM/yyyy H:MM”);oappoint.Start=DateTime.Parse(格式化的_日期);//设置开始日期oappoiment.End=DateTime.Parse(格式化的_日期);//结束日期正如我告诉过你的,不要将格式化的字符串解析为Datetime,如果你这样做,Datetime将根据你的文化设置。。。这是“MM/dd/yyyy”,好的,我知道了,使用这个
DateTime t1=DateTime.ParseExact(DateTimeVal,“MM/dd/yyyy H:MM”,null)代码>很抱歉再次与您相邻;但是如何在不进行解析的情况下将字符串分配给datetime呢?