Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 带有Asp.Net MVC日期格式映射的jQuery.ui.datepicker_Asp.net Mvc_Jquery Ui_Datepicker_Date Format - Fatal编程技术网

Asp.net mvc 带有Asp.Net MVC日期格式映射的jQuery.ui.datepicker

Asp.net mvc 带有Asp.Net MVC日期格式映射的jQuery.ui.datepicker,asp.net-mvc,jquery-ui,datepicker,date-format,Asp.net Mvc,Jquery Ui,Datepicker,Date Format,是否有人将c#dateFormat映射到datePicker dateFormat,因为我已经知道c#dateFormat,我不想每次构建自定义日期格式时都检查datePicker文档 例如,我希望能够在我的助手dateFormat中指定'dd/MM/yy'(c#),并将其转换为'dd/MM/yy'日期选择器也许您可以使用类似以下内容: <%= Html.TextBoxFor(x => x.SomeDate, new { @class = "datebox", dateformat

是否有人将c#dateFormat映射到datePicker dateFormat,因为我已经知道c#dateFormat,我不想每次构建自定义日期格式时都检查datePicker文档


例如,我希望能够在我的助手dateFormat中指定'dd/MM/yy'(c#),并将其转换为'dd/MM/yy'日期选择器

也许您可以使用类似以下内容:

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

一种可能的方法是直接将.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;
}

原始来源:

这不是我想要的,我想要的是使用自定义帮助程序在c#中指定与日期选择器相同的格式,因此可以在c#中指定一个转换,例如,日期选择器中的“dd/mm/yy”在c#中是“dd/mm/yy”。
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;
}