0

私は次のようにjquery datetimepickerを使用しています:

<script type="text/javascript">
$(document).ready(function () {
    $("#LessonDateTime").datetimepicker(
    );
});
</script>

テキストボックスに値がない場合、デフォルトで今日の日付になり、値がある場合、日時ピッカーは下の画像に示すように 1899 に移動します。 ここに画像の説明を入力

以下のビューモデルを使用してバインドしています。

public class AppointmentViewModel
{
    public long? UserId { get; set; }
    public long Id { get; set; }
    public string AppointmentInstructorName { get; set; }

    [DisplayFormat(ApplyFormatInEditMode =true, DataFormatString ="{0:dd/MMM/yyyy h:mm tt}")]
    public DateTime? LessonDateTime { get; set; }

    public string AppointmentLessonAddress { get; set; }


}

見る:

 @{ViewBag.PageTitle = "Edit an Appointment";}
 <script type="text/javascript">
 $(document).ready(function () {
    $("#LessonDateTime").datetimepicker(
    );
});
</script>
 @using (Html.BeginForm())
{
@Html.AntiForgeryToken()

@Html.Hidden("userId", Model.UserId)
<div class="row">
    <div class="col-md-8">
        <div class="panel">

            <div class="panel-heading tabbable" tabindex="0"><h1>Edit Appointment Details</h1></div>

            <div class="panel-body">

                <div class="form-group row">
                    <div class="col-sm-6">
                        @Html.LabelFor(model => model.AppointmentInstructorName, "Instructor Name", htmlAttributes: new { @class = "control-label" })
                        @Html.EditorFor(model => model.AppointmentInstructorName, new { htmlAttributes = new { @class = "form-control" } })
                    </div>

                </div>
                <div class="form-group row">
                    <div class="col-sm-6">

                        @Html.LabelFor(model => model.LessonDateTime, "Lesson Date and Time", htmlAttributes: new { @class = "control-label" })
                        @Html.EditorFor(model => model.LessonDateTime, new { htmlAttributes = new { @class = "form-control" } })
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-sm-6">
                        @Html.LabelFor(model => model.AppointmentLessonAddress, "Address (if different)", htmlAttributes: new { @class = "control-label" })
                        @Html.EditorFor(model => model.AppointmentLessonAddress, new { htmlAttributes = new { @class = "form-control" } })
                    </div>



                </div>
                <div class="form-group row">
                    <div class="col-sm-6">
                        <input type="submit" class="btn btn-primary form-control" value="Submit" />
                        </div>
                    </div>
                </div>




        </div>
    </div>


</div>



}
4

3 に答える 3

0

追加useCurrent:falseは私のために働いた

$(function () {
        $('#LessonDateTime').datetimepicker({
            useCurrent: false                   
        });
    });
于 2016-08-30T12:28:04.817 に答える
0

タイムスタンプを取得しています。「通常の」日付に変換できます。しかし、最良の方法は、datetimepicker で日付形式の種類を設定することです

于 2016-08-30T06:11:52.020 に答える
0

以下に示すように、このコードを datetimepicker に記述できます。defaultDate indatetimepicker`を宣言する必要があります。

 $(function () {
            $('#LessonDateTime').datetimepicker({
                defaultDate: "11/1/2013",
                useCurrent: false,                   
            });
        });

詳細については、https://eonasdan.github.io/bootstrap-datetimepicker/を参照してください。

于 2016-08-30T05:37:11.390 に答える