DateTime Format Exceptions and Computer Date Format
My team is building a web app in Asp.Net with C# on SQL Server Express R2. Currently, we're developing in Visual Studio 2010 with the database hosted on a separate server. We're running the app on the development server of our home computers.
If I change my home computer date format to d/M/yyyy and the date format I want in M/d/yyyy for my code, I get errors. It accepts dates up to the 12th day of the month because it assumes the day field is actually the month field. After that, I get a giant format exception when I try to convert the string to a DateTime. This is a huge problem and our client wants the date format in M/d/yyyy.
I've tried everything I can think of!
Changing the web.config doesn't work:
<globalization culture="auto:en-US" uiCulture="auto:en" />
Using a format when converting:
String strDate = myDate.ToString("M/d/yyyy")
Using a format and culture info when converting:
DateTime myDate = Convert.ToDateTime(strDate, new CultureInfo("en-CA"));
None of this works! We're in a real pinch right now, I'd appreciate any information on the matter. At the moment, I can only hope when we run it on the ac开发者_如何学编程tual server, it will run correctly if the server's date is formatted properly.
DateTime.ParseExact("12/15/2009", "M/d/yyyy", new CultureInfo("en-CA"));
This should work
精彩评论