VB.NET:如何将字符串转换为日期?

前端之家收集整理的这篇文章主要介绍了VB.NET:如何将字符串转换为日期?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我通过表单中的文本文件通过SSIS包进入字符串:
"20090910" (string)

它需要

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

有什么建议?

试试 DateTime.ParseExact()

来自MSDN的数据示例:

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
原文链接:https://www.f2er.com/vb/255070.html

猜你在找的VB相关文章