开发者

vb.net convert string to date

开发者 https://www.devze.com 2023-01-14 00:50 出处:网络
how do i convert the string 30.10.200开发者_JAVA技巧9in date? (dd.mm.yyyy) thanks :>You could use the TryParseExact function:

how do i convert the string

30.10.200开发者_JAVA技巧9 in date? (dd.mm.yyyy)

thanks :>


You could use the TryParseExact function:

Dim DateStr = "30.10.2009"
Dim Dt As DateTime
If DateTime.TryParseExact(DateStr, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, Dt) Then
    ' The date was successfully parsed => use the Dt variable
End If


You can use DateTime.ParseExact:

Dim culture as CultureInfo = new CultureInfo("en-US")
Dim date as DateTime = DateTime.ParseExact("30.10.2009", "dd.MM.yyyy", culture)

See custom datetime format strings on MSDN.

If you are not sure that the format is exactly as mentioned, you can use TryParseExact to avoid an exception being thrown.

0

精彩评论

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