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


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

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.

1 comment:

  1. This is a nice article..
    Its very easy to understand ..
    And this article is using to learn something about it.., c#, javascript
    Thanks a lot..!