How to (try)parse a single String to DateTime in “DD/MM/YYYY” format? (VB.Net)

后端 未结 1 1569
暗喜
暗喜 2021-01-14 18:18

How to (try)parse a single String to DateTime in \"DD/MM/YYYY\" format? (VB.Net)

For example: I use input string \"30/12/1999\" (30 December 1999), how to (try)parse

相关标签:
1条回答
  • 2021-01-14 18:54

    Try this:

    Dim date As Datetime = DateTime.ParseExact(_
        yourString, "dd/MM/yyyy", CultureInfo.InvariantCulture)
    

    This will throw an exception if yourString does not match the format you specify. If you do not want an exception in this case then do this:

    Dim date As Date    
    Date.TryParseExact(dateString, "dd/MM/yyyy", CultureInfo.CurrentCulture, _
                          DateTimeStyles.None, date)
    
    0 讨论(0)
提交回复
热议问题