Friday, June 3, 2011

Must set culture value for using CompareValidator for date formatting.




culture en-US : M/dd/yyyy
culture en-GB : dd/MM/yyyy , dd-MM-yyyy , dd.MM.yyyy


must set
System.Threading.Thread.CurrentThread.CurrentCulture

not
System.Threading.Thread.CurrentThread.CurrentUICulture



System.Threading.
System.Threading.
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB");


http://msdn.microsoft.com/en-us/goglobal/bb688124


The easiest and most efficient way of formatting dates in the .NET world is to take advantage of the DateTime structure, which provides methods allowing you to perform culture-sensitive operations on DateTime. Use the DateTimeFormatInfo class to format and display a DateTime based on a culture-specific standard. DateTimeFormatInfo defines how DateTime values are formatted and displayed, depending on the culture. For example, using the ShortDatePattern, the date April 24, 2001, is formatted as 4/24/2001 for the "en-US" culture and 24/04/2001 for the "en-GB"-English (United Kingdom)-culture.
An instance of DateTimeFormatInfo can be created for a specific culture, but not for a neutral culture. A neutral culture does not provide enough information to display the correct date format. You just saw that English (United States) and English (United Kingdom) share the same neutral culture-English-and yet have completely different formatting for the date.

No comments:

Post a Comment

Odds Ratio (OR), Logistic Regression Interpretation vs. Prediction, and Ordinal Logistic Regression

An odds ratio (OR) measures the association between an exposure and an outcome. It represents the odds that an outcome will occur given ...