I'm using jQuery's datepicker plugin in .NET ASP MVC3 intranet application. User that use application have offices in different countries and different locale. This is why I wanted to integrate Thread.CurrentThread.CurrentCulture.DateTimeFormat with jQuery datepicker plugin. My first solution was to create helper extension method:
public static string jQueryDatePickerFormat(this HtmlHelper helper)
{
return Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;
}
and set dateFormat option in javascript like this:
$("#StartDate").datepicker({ dateFormat: '@Html.jQueryDatePickerFormat()' });
Soon after I realized that datepicker's dateFormat option supports formats that have different implementation from format in .NET.
For instance: Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern for pl-PL returns yyyy-MM-dd (it will format date as 2010-01-01), whereas the same format in datePicker will format the same date as 20102010 January 01. I quickly adapted my helper method and applied 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 works, but I wait for the moment when other issues will emerge. Is there any simpley way to implement .NET locale settings into jQuery's datePicker plugin?
Thanks,Pawel
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…