在vb.net中将字符串转换为日期时间

在vb.net中将字符串转换为日期时间,vb.net,string,datetime,Vb.net,String,Datetime,我的约会时间如下所示: 201210120956 ccyyMMDDhhmm 当我尝试这个: Dim convertedDate As Date = Date.Parse(DateString) Return convertedDate 我得到这个: #10/12/2012# 我在浪费时间 我读过这篇文章,但当我使用datetime.ParseExact()时,我得到: 无法解析符号“ParseExact” 有没有办法不使用子字符串将其转换为日期时间?直接转换?您可以尝试使用ParseExa

我的约会时间如下所示:

201210120956
ccyyMMDDhhmm
当我尝试这个:

Dim convertedDate As Date = Date.Parse(DateString)
Return convertedDate
我得到这个:

#10/12/2012#
我在浪费时间

我读过这篇文章,但当我使用
datetime.ParseExact()
时,我得到:

无法解析符号“ParseExact”


有没有办法不使用子字符串将其转换为日期时间?直接转换?

您可以尝试使用
ParseExact
方法

样品

Dim format As String  
format = "d" 
Dim provider As CultureInfo = CultureInfo.InvariantCulture
result = Date.ParseExact(DateString, format, provider)

将解码模式传递给ParseExact

Dim d as string = "201210120956"
Dim dt = DateTime.ParseExact(d, "yyyyMMddhhmm", Nothing)
ParseExact仅在Net FrameWork 2.0中提供。

如果您仍然使用1.1,则可以使用Parse,但您需要提供适合字符串的IFormatProvider作为替代,如果在日期和时间之间放置空格,
DateTime.Parse将为您识别格式。这是最简单的。(如果
ParseExact
仍然没有被识别)

应该能够使用ParseExact,它已经存在了。net2关于DateTime.Parse的内容是什么?也许我应该问问为什么ParseExact没有被识别。。似乎没有人看到这篇文章的这一部分……当我使用DateTime.Parse()时,我得到“字符串未被识别为有效的DateTime”我不知道为什么visual studio没有看到ParseExact,但它现在正在运行…我输入了DateTime.Parse只是想看看它是否也找不到它。我已经阅读了这个转换字符串到DateTime vb.net,但是当我使用DateTime.ParseExact()时我得到:无法解析符号“ParseExact”DateTime。ParseExact是2.0版的NET Framework中存在的DateTime类型的方法。您使用的是哪个版本的框架?可能因为我进入了项目属性,它让它再次查看了我的设置:我已经阅读了这个转换字符串到datetime vb.net,但是当我使用datetime.ParseExact()时,我得到:无法解析符号“ParseExact”