如何从DatePicker ui jquery中删除时间

Rap*_*ael 10 asp.net asp.net-mvc jquery jquery-ui datepicker

我正在使用带有asp.net mvc的jquery ui datepicker,当网页打开时,它会在datepicker的文本框中显示日期和时间(2014/10/16 00:00:00),但如果我在文本框中为datepicker选择一个日期,它只显示日期.我不想看时间,有什么不对?

谢谢!

模型中的属性设置如下

[DataType(DataType.Date)]
[Required(ErrorMessageResourceType = typeof(Ressources.Resources), ErrorMessageResourceName="ErrorStartDateRequired")]
[Display(Name = "DateStarted", ResourceType = typeof(Ressources.Resources))]
public DateTime DateStarted { get; set; }
Run Code Online (Sandbox Code Playgroud)

我的日期选择器在我的网页中设置如下:

@section scripts{
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
    var anchor = document.getElementById('@Model.Anchor');
    anchor.scrollIntoView(true);

    var d = new Date(@Model.Project.DateStarted.Year, @Model.Project.DateStarted.Month, @Model.Project.DateStarted.Day);
    $("#datePickerStartDate").datepicker({
        dateFormat: "yy/mm/dd",
        showOtherMonths: true,
        selectOtherMonths: true,
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        gotoCurrent: true,
        defaultDate: d
    });
});
Run Code Online (Sandbox Code Playgroud)

}

这就是控件在网页中的显示方式(cshtml)

<div class="form-group">
    @Html.LabelFor(model => model.Project.DateStarted, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.TextBoxFor(model => model.Project.DateStarted, new { id = "datePickerStartDate" })
        @Html.ValidationMessageFor(model => model.Project.DateStarted)
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Rap*_*ael 33

我终于找到了答案.我在视图方面添加了"{0:d}".

<div class="form-group">
    @Html.LabelFor(model => model.Project.DateFinished, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.TextBoxFor(model => model.Project.DateFinished, "{0:d}", new { id = "datePickerEndDate" })
        @Html.ValidationMessageFor(model => model.Project.DateFinished)
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

谢谢


小智 0

将脚本更改为这种方式以避免使用当前日期的时间避免 var d 分配

<script>
        $("#datePickerStartDate").datepicker(
            {
                dateFormat: "yy/mm/dd",
                showOtherMonths: true,
                selectOtherMonths: true,
                showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                gotoCurrent: true,
            }).datepicker("setDate", new Date());
 </script>
Run Code Online (Sandbox Code Playgroud)