开发者

VB.NET: How to convert string to Date?

I have string coming开发者_StackOverflow中文版 in through an SSIS package via text file in form:

"20090910" (string)

and it needs to be

2010-09-01 00:00:00 (Date)

Any suggestions?


Try DateTime.ParseExact()

Example from MSDN with your data:

Dim dateString, format As String  
Dim result As Date
Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture

' Parse date and time with custom specifier.
dateString = "20090910"
format = "yyyyMMdd"        
Try
   result = Date.ParseExact(dateString, format, provider)
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString())
   Console.ReadLine()
Catch e As FormatException
   Console.WriteLine("{0} is not in the correct format.", dateString)
End Try 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜