【问题标题】:Twitter Bootstrap datepicker Formatting IssueTwitter Bootstrap 日期选择器格式问题
【发布时间】:2013-05-23 10:33:24
【问题描述】:

我在 mvc4 应用程序中使用 twitter boostrap datepicker。在我的模型中,我将日期属性设置为-

 [DisplayName("Date Last Modified")]
 [DisplayFormat(DataFormatString = "{0:dd/MMM/yyyy}")]
 public DateTime? EmpLastModified { get; set; }

Jquery datepicker 是 as-

@if (Model.HasValue && ((DateTime)Model.Value).Year > 1500)
{
   @Html.TextBox("", String.Format("{0:dd/MMM/yyyy }", Model.Value), new { @class =      "textbox", @style = "width:125px;" })
}
else {
@Html.TextBox("", String.Format("{0:dd/MMM/yyyy}", DateTime.Now), new { @class =   "textbox", @style = "width:125px;" })
}

<script type="text/javascript">
$(document).ready(function () {

    $("#@id").datepicker
        ({
            dateFormat: '0:dd/MMM/yyyy',
            showStatus: true,
            showWeeks: true,
            highlightWeek: true,
            changeMonth: true,
            changeYear: true,
            numberOfMonths: 1,
            showAnim: "scale",
            showOptions: {
                origin: ["top", "left"]
            }
        });
    });

日期选择器应显示 23-May-2013 作为日期,但它显示 11/23/2013 而在 firebug 中显示

<input id="EmpDateAdded" class="textbox" type="text" value="23-May-2013" style="width:125px;" name="EmpDateAdded" data-val-date="The field Date Added To System must be a date." data-val="true">

我使用 datepicker.css 和 bootstrap-datepicker.js, date.format.js

请帮忙。提前致谢

【问题讨论】:

    标签: asp.net-mvc-4 twitter-bootstrap jquery-ui-datepicker datepicker


    【解决方案1】:

    日期选择器的格式字符串与 .NET 不同。假设您使用的是eternicode version,请将其用作日期选择器的格式指南(摘自文档):

    Default: 'mm/dd/yyyy'
    
    The date format, combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy.
    
    d, dd: Numeric date, no leading zero and leading zero, respectively. Eg, 5, 05.
    D, DD: Abbreviated and full weekday names, respectively. Eg, Mon, Monday.
    m, mm: Numeric month, no leading zero and leading zero, respectively. Eg, 7, 07.
    M, MM: Abbreviated and full month names, respectively. Eg, Jan, January
    yy, yyyy: 2- and 4-digit years, respectively. Eg, 12, 2012.
    

    【讨论】:

    • 非常感谢......它明白了......我需要更改 bootstrap-datepicker.js 中的日期格式
    【解决方案2】:

    我会推荐你​​使用 moment.js 如果您能够在工作中使用任何库。

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 2013-09-30
      • 2015-07-05
      • 2017-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多