質問

c#dateformatにc#dateformatをマッピングした人はどこかにあります。c#dateformatを既に知っているので、カスタム日付形式を作成するたびにdatepickerドキュメントを確認する必要はありません。

Exmpleについては、「DD/MM/YY」(C#)のヘルパーデートフォーマットで指定できるようになり、「DD/MM/YY」DatePickerに変換します。

役に立ちましたか?

解決

考えられるアプローチの1つは、次のコードで確認できるように、.NET形式の指定器をjQueryのカウンターパートに直接置き換えることです。

public static string ConvertDateFormat(string format)
{
    string currentFormat = format;

    // Convert the date
    currentFormat = currentFormat.Replace("dddd", "DD");
    currentFormat = currentFormat.Replace("ddd", "D");

    // Convert month
    if (currentFormat.Contains("MMMM"))
    {
        currentFormat = currentFormat.Replace("MMMM", "MM");
    }
    else if (currentFormat.Contains("MMM"))
    {
        currentFormat = currentFormat.Replace("MMM", "M");
    }
    else if (currentFormat.Contains("MM"))
    {
        currentFormat = currentFormat.Replace("MM", "mm");
    }
    else
    {
        currentFormat = currentFormat.Replace("M", "m");
    }

    // Convert year
    currentFormat = currentFormat.Contains("yyyy") ? currentFormat.Replace("yyyy", "yy") : currentFormat.Replace("yy", "y");

    return currentFormat;
}

元の出典: http://rajeeshcv.com/2010/02/28/jqueryui-datepicker-in-asp-net-mvc/

他のヒント

たぶんあなたはこのようなものを使うことができます:

<%= Html.TextBoxFor(x => x.SomeDate, new { @class = "datebox", dateformat = "dd/mm/yy" })%>

この:

$(function() {
    $("input.datebox").each(function() {
        $(this).datepicker({ dateFormat: $(this).attr("dateFormat") });
    });
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top