gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:06:19 26 4
gpt4 key购买 nike

我有字符串通过文本文件通过 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

关于VB.NET:如何将字符串转换为日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4338658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com