I am using jQuery datepicker plugin in .NET ASP MVC3 intranet application. The user using the application has offices in different countries and different language standards. This is why I wanted to integrate Thread.CurrentThread.CurrentCulture.DateTimeFormat with the jQuery datepicker plugin . My first solution was to create a helper extension method:
public static string jQueryDatePickerFormat(this HtmlHelper helper)
{
return Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;
}
and set the dateFormat parameter in javascript like this:
$("#StartDate").datepicker({ dateFormat: '@Html.jQueryDatePickerFormat()' });
Shortly after I realized that the datepicker dateFormat parameter supports formats that have a different implementation from the format in .NET.
For example: Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern for PL-PL returns yyyy-MM-dd (it will format the date as 2010-01-01), while the same format in datePicker will format the same date as 20102010 January 01 . I quickly adapted my helper method and applied the quick fix Replace ("yyyy", "yy"). Replace ("MM", "mm") :
public static string jQueryDatePickerFormat(this HtmlHelper helper)
{
return Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace("yyyy", "yy").Replace("MM", "mm");
}
I work, but I'm waiting for the moment when other problems appear. Is there an easy way to implement .NET language settings in the jQuery datePicker plugin?
Thanks Pawel