jQuery的日期选择器的日期格式 - 如何与.NET当前区域性DateTimeFormat整合 [英] jQuery datepicker's dateFormat - how to integrate with .NET current culture DateTimeFormat

查看:187
本文介绍了jQuery的日期选择器的日期格式 - 如何与.NET当前区域性DateTimeFormat整合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.NET中的ASP MVC3 Intranet应用程序jQuery的日期选择器插件。用户使用的应用程序在不同的国家和不同的地区办事处。这就是为什么我希望集成的 Thread.CurrentThread.CurrentCulture.DateTimeFormat 的jQuery插件,日期选择器即可。我的第一个解决方案是创建辅助扩展方法:

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;
    }

和将日期格式在这样的JavaScript选项:

and set dateFormat option in javascript like this:

$("#StartDate").datepicker({ dateFormat: '@Html.jQueryDatePickerFormat()' });

后不久,我意识到,日期选择器的日期格式选项支持具有格式.NET不同的实现形式。

Soon after I realized that datepicker's dateFormat option supports formats that have different implementation from format in .NET.

例如: Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern 作为PL-PL回报 YYYY-MM-DD (将格式化日期2010-01-01 ),而在相同格式的日期选择器将格式化同日的 20102010 1月1日。我很快就适应了我的辅助方法,并应用于速战速决的替换(YYYY,YY)更换(MM,MM)

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");
    }

我的作品,但我等待,当其他问题将出现的时刻。有没有实现.NET区域设置成jQuery的日期选择器插件的任何simpley方式?

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?

谢谢你,帕维尔

推荐答案

在$ C $的CProject文章jQueryUI的日期选择在ASP.NET MVC
HTTP://www.$c$cproject .COM /用品/ 62031 / jQueryUI的,日期选择器功能于ASP-NET-MVC 具有的功能,做你想要的到底是什么

The codeproject article JQueryUI Datepicker in ASP.NET MVC http://www.codeproject.com/Articles/62031/JQueryUI-Datepicker-in-ASP-NET-MVC has function that does exactly what you wanted

    /// Converts the .net supported date format current culture 
/// format into JQuery Datepicker format.
/// </summary>
/// <param name="html">HtmlHelper object.</param>
/// <param name="format">Date format supported by .NET.</param>
/// <returns>Format string that supported in JQuery Datepicker.</returns>
public static string ConvertDateFormat(this HtmlHelper html, string format)

我也张贴在做opposite- <一个函数href=\"http://geekswithblogs.net/mnf/archive/2012/04/14/translate-jquery-ui-datepicker-format-to-.net-date-format.aspx\"相对=nofollow>翻译jQuery UI的日期选择器格式的.Net日期格式

这篇关于jQuery的日期选择器的日期格式 - 如何与.NET当前区域性DateTimeFormat整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆