将逗号分隔的字符串转换为日期时间 [英] Convert comma separated string to datetime

查看:421
本文介绍了将逗号分隔的字符串转换为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Exchange Web服务具有一种采用以下格式的DateTime的方法

The Exchange webservice has a method that takes the DateTime in the format below

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

我有一个字符串,该字符串是通过将各个字段连接起来以形成我的字符串的日期而形成的:

I have a string which is formed by concatenating various fields to form the date my string is as below:

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

但是,如果我尝试将字符串解析为日期,则会出现错误字符串未被识别为有效的DateTime".

But if i try to to parse my string as the date it gives the error "String was not recognized as a valid DateTime".

   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);

这篇关于将逗号分隔的字符串转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆