In my web.config file I have this line:
<globalization culture="auto:en-GB" uiCulture="auto:en-GB" requestEncoding="utf-8" responseEncoding="utf-8" responseHeaderEncoding="utf-8"/>
ASP.Net nicely takes care of all date/time formats. Applying the following code in a sample page...
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
txt.Text = New DateTime(2010, 1, 25).ToString()
End Sub
Protected Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
Dim dt As DateTime = Convert.ToDateTime(txt.Text.Trim())
Trace.Warn(dt.ToString())
End Sub
With a browser, set to English (UK) I see the date displayed as
25/01/2010 00:00:00
On pressing the button and converting this back to a DateTime value, it works perfectly.
If I change my browser (Chrome) settings to Norwegian Bokmal, and load the page, I see this:
25.01.2010 00.00.00
This again is correct, but, if I then submit the form, ASP.Net crashes:
String was not recognized as a valid DateTime.
Line 9: Dim dt As DateTime = Convert.ToDateTime(txt.Text.Trim())
Why is this happening? Surely if ASP.Net has the sense to display dates based on culture settings, it should be able to read them? I've tried English UK and English US and both work as expected, plus others, so it seems linked to Norwegian in some manner.