将字符串转换为vb.net中的datetime [英] Convert string to datetime in vb.net
问题描述
我的日期时间如下所示:
I have a datetime that looks like this:
201210120956
ccyyMMDDhhmm
当我尝试这个:
Dim convertedDate As Date = Date.Parse(DateString)
Return convertedDate
我收到这个:
#10/12/2012#
我正在失去时间。
我已经读过这个将字符串转换为datetime vb.net ,但是当我使用 datetime.ParseExact()
我得到:
I've read this convert string to datetime vb.net but when I use datetime.ParseExact()
I get:
无法解析符号'ParseExact'
cannot resolve symbol 'ParseExact'
有没有办法将它转换为日期时间而不使用子字符串?直接转换?
Is there a way to convert this to a date time without using substring? A straight conversion?
推荐答案
将解码模式传递给ParseExact
Pass the decode pattern to ParseExact
Dim d as string = "201210120956"
Dim dt = DateTime.ParseExact(d, "yyyyMMddhhmm", Nothing)
ParseExact仅可用于Net FrameWork 2.0中的 。
如果您仍然在1.1,您可以使用Parse,但是您需要为您的字符串
ParseExact is available only from Net FrameWork 2.0.
If you are still on 1.1 you could use Parse, but you need to provide the IFormatProvider adequate to your string
这篇关于将字符串转换为vb.net中的datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!