ASP.Net VB DateTime ParseExact function is similar to Parse Function that we learnt in the previous tutorial of ASP.Net VB DateTime Parse Function. DateTime.ParseExact function support 1 extra parameter to specify the expected DateTime format passed in the string parameter. While using the DateTime parseExact function in ASP.Net VB code you have to use IFormatProvider Interface to pass the information about the current or desired Culture. IFormatProvider enables you to parse the DateTime string to different Cultures and Format Date into that Culture with different styles.
Dim Culture As IFormatProvider
' For GB Culture Pass en-GB
Culture = New CultureInfo("en-GB", True)
' For French Culture Pass fr-Fr
Culture = New CultureInfo("fr-Fr", True)
Both cultures mentioned above accept the different DateTime Formats.
If you are using DateTime.Parse then you have to pass the MM/dd/yyyy hh:mm:ss Format of DateTime for French culture and dd/MM/yyyy hh:mm:ss for US English culture. You have to check the format for different cultures by changing the position of month and day.
Dim myDateTimeString As String
' coz date string is in dd/MM/yyyy
Response.Write(dt.Day & "/" & dt.Month & "/" & dt.Year)
Response.Write("<br>")
Response.Write(dt.ToString("dddd"))
Response.Write(dt.ToString("MMMM"))
Output:
22/7/2008 Tuesday July
Note: To use CultureInfo import System.Globalization namespace.
Currently rated 5.0 by 1 people
Tags: asp.net 2.0, asp.net vb datetime parseexact function, asp.net vb datetime parse function, asp.net convert string to date, vb datetime, vb tostring function, asp.net datetime, vb convert string to date, c# datetime, asp.net c# datetime, datetime.parseexact function, convert.todatetime function, datetime.parse function, vb datetime iformatprovider, c# datetime iformatprovider
8/23/2008 8:47:46 PM