Last post Nov 03, 2017 09:20 AM by PatriceSc
Nov 02, 2017 02:22 AM|arnabjee|LINK
Based on the locale of the business, in my ASP.NET application I change the value of Thread.CurrentThread.CurrentCulture. Throughout my application I use the following syntax to convert a string to DateTime : DateTime.Parse(<datestring>, culture, System.Globalization.DateTimeStyles.AssumeLocal).
This is working fine when uploaded in Azure both for en-US and en-IE locales. When I debug the application in my local machine which is running Windows 10, this code is throwing exception. I found out that the culture is set to en-US , the datestring is in
MM/dd/yyyy as expected in en-US locale. Investigating further I found that even though the Thread.CurrentThread.CurrentCulture is set to en-US in my application but the short date format remains as dd/MM/yyyy. This is the reason for the exception.
Could someone come up with a solution as I am stuck in debug mode everywhere.
I don't want to change the syntax for parsing as it is working fine in production and also it is used in n number of places throughout the application.
Maybe a settings change in my local machine?
Thanks and regards,
Nov 03, 2017 09:20 AM|PatriceSc|LINK
You saw that by directly showing the short date pattern ? I would likely try a console or a web page showing really the pattern:
var c = new System.Globalization.CultureInfo("en-us");
c = new System.Globalization.CultureInfo("en-gb");
Try perhaps https://msdn.microsoft.com/en-us/library/ms172469(v=vs.90).aspx
and maybe https://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.unregister(v=vs.90).aspx assuming
this culture was really customized.
How do do you see the short format is this way ?