NET DateTime Formats

VbNet · Console

/Program.vb

Imports System
Imports System.Globalization
Imports System.Collections.Generic
				
Public Module Module1
	Public Sub Main()
	    Dim fmtList As New List(Of String)    ' dupe filter
        Dim n As Integer = 1

		Dim dtRT As DateTime = DateTime.Now
        Dim strRT As String
        Dim bRT As Boolean

        ' French: "fr-FR"; German: "de-DE" etc
        ' Spain: "es-ES", Croatia "hr-HR", Czech "cs-CZ"
		' Canadian "en-CA"; Finnish "fi-FI"; Turkey tr-TR
		Dim thisCult As New CultureInfo("it-IT")
        Dim dtInfo = DateTimeFormatInfo.GetInstance(thisCult)

		
		console.WriteLine("All DateTime Formats for {0}:",thisCult.DisplayName)
        For Each fmt As String In dtInfo.GetAllDateTimePatterns()
            ' only print unique ones
		    If fmtList.Contains(fmt) = False Then
			
				fmtList.Add(fmt)
			
							
				' Roundtrip test:
				'   Get string name in this culture too for Month Names
				' or Finnish 'heinäkuuta' wont match 'July'
				strRT = dtRT.ToString(fmt, thisCult)
			
				' use the most restrictive test
                bRT = DateTime.TryParseExact(strRT, fmt, thisCult, DateTimeStyles.None, dtRT)
				                
				Console.WriteLine("{0} {1} (Parse from: {2})", n.ToString("000"), fmt.PadRight(42), bRT.ToString)
                n += 1
            End If
        Next
		

	End Sub
End Module
;