【问题标题】:Why a jquery datepicker change days for months?为什么 jquery datepicker 将日期更改为几个月?
【发布时间】:2013-10-09 18:28:08
【问题描述】:

我正在处理 MVC 项目,并且使用 jquery datepicker 我在帖子中遇到了问题。 我使用包含文本框和 jquery 函数的局部视图。像这样:

 @model Nullable<System.DateTime>
<div class="row-fluid input-append">
    @if (Model.HasValue && Model.Value != DateTime.MinValue)
    {
        @Html.TextBox("", String.Format("{0:dd/MM/yyyy}", Model.Value), new { @class = "input-small date-picker",@readonly = true, style = "cursor:pointer; background-color: #FFFFFF; text-align: center;" })
    }
    else
    {
        @Html.TextBox("", String.Format("{0:dd/MM/yyyy}", ""), new { @class = "input-small date-picker", @readonly = true, style = "cursor:pointer; background-color: #FFFFFF; text-align: center;" })
    }
</div>

@{
    string name = ViewData.TemplateInfo.HtmlFieldPrefix;
    string id = name.Replace(".", "_");
}

<script type="text/javascript">
    $('#@id').datepicker({
        dateFormat: 'dd/mm/yy',
        todayHighlight: true,
        clearBtn: true,
        forceParse: true,
        autoclose: true,
    });
</script>

当我格式化日期选择器以选择以天/月/年为单位的日期时,当我选择日期时,格式就可以了!我的意思是,我在日历中选择了 8 月 5 日,文本框显示 05/08/2013,但是当单击保存时出现问题,因为在控制器中,日期的值从天更改为月! 谢谢!

【问题讨论】:

  • mm/dd/yyyy 是美国的标准日期格式。我会假设您的问题是由您的部分代码认为您的语言环境不在某个地方引起的。也许是数据库?
  • 是的,因此我在 dateFormat 中设置了“dd/mm/yy”.. 但不起作用,因为在控制器中我得到了不同的格式(“mm/dd/yy”)跨度>

标签: c# jquery asp.net-mvc jquery-ui-datepicker


【解决方案1】:

web.config 中添加以下内容:

<system.web>
    <globalization culture="en-GB" uiCulture="en-GB" />
</system.web>

它应该改变默认的日期解析。

【讨论】:

  • @Blazemonger - True...我刚刚看到dateFormat: 'dd/mm/yy' 并认为“这就是我使用的 - 他一定在英国!”
猜你喜欢
  • 2016-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多