Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
- Dim str = "1/4/19" ' test data '
- If cbDateFormat.SelectedIndex = -1 Then
- MsgBox("Please select the date format.")
- Exit Sub
- End If
- Dim dateFormat = ""
- Select Case cbDateFormat.Text
- Case "DD/MM/YYYY"
- dateFormat = "d/M/yyyy"
- Case "MM/DD/YYYY"
- dateFormat = "M/d/yyyy"
- Case "DD/MM/YY"
- dateFormat = "d/M/yy"
- Case "MM/DD/YY"
- dateFormat = "M/d/yy"
- Case Else
- Throw New Exception("Date format not found.")
- End Select
- Dim d As DateTime
- If DateTime.TryParseExact(str, dateFormat, Globalization.CultureInfo.InvariantCulture, Nothing, d) Then
- ' d now holds the datetime '
- MsgBox(d.ToString("dd-MMM-yyyy"))
- End If
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- cbDateFormat.Items.AddRange({"DD/MM/YYYY", "MM/DD/YYYY", "DD/MM/YY", "MM/DD/YY"})
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement