c# - 将逗号分隔的字符串转换为日期时间

标签 c# exchangewebservices

Exchange Web 服务有一个方法,采用以下格式获取日期时间

  appointment.Start = new DateTime(2014, 03, 04, 11, 30, 00);

我有一个字符串,它是通过连接各个字段形成的日期而形成的,我的字符串如下:

   string date="2014,03,04,11,00,00"

但是,如果我尝试将字符串解析为日期,则会出现错误“字符串未被识别为有效的日期时间”。

   DateTime.Parse(date)

最佳答案

您可以使用DateTime.ParseExact:

string date = "2014,03,04,11,00,00";
DateTime dateTime = DateTime.ParseExact(date, "yyyy,MM,dd,HH,mm,ss", CultureInfo.CurrentCulture);

关于c# - 将逗号分隔的字符串转换为日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21548184/

相关文章:

c# - 使用参数启动程序

calendar - EWS : Access shared calendars

exchangewebservices - 如何使用托管 API 取消订阅 EWS 推送通知

c# - Exchange FindItem 响应一个项目 ID 和多个项目 ID 的不同属性集

java - 使用 Exchange Web 服务的 Maven 项目中缺少类

c# - Exchange Web 服务托管 API : How can I perform Recurrence Expansion through the FindItem Method?

C# - 使用 Refit 传递 Web Api 对象

c# - 为什么不编译多次使用 PreApplicationStartMethodAttribute?

c# - 在 Entity Framework 6 中使用自定义约定控制列映射

c# - 通过对象字段搜索 ObservableCollection