简体   繁体   English

所选日期大部分时间为 01/01/0001 00:00:00

[英]Selected date is most of the time 01/01/0001 00:00:00

When selecting the date and time with a custom DateTimePicker ( https://tempusdominus.github.io/bootstrap-4/Usage/ ).使用自定义 DateTimePicker ( https://tempusdominus.github.io/bootstrap-4/Usage/ ) 选择日期和时间时。 When the submit button is clicked 9 out of 10 times the date and time is this:当提交按钮被点击 10 次中的 9 次时,日期和时间是这样的:

01/01/0001 00:00:00

Code on the Razor page: Razor 页面上的代码:

        <div class="form-group row">
            <label class="col-sm-2 col-form-label">Date and time :</label>
            <div class="col-sm-4">
                <div class="input-group date" id="datetimepicker1" data-target-input="nearest">
                    <input asp-for="IncidentDateAndTime" type="text" class="form-control datetimepicker-input" data-target="#datetimepicker1" />
                    <div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
                        <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                    </div>
                </div>
            </div>
        </div>

The script on the same page:同一页面上的脚本:

 $(function () {
    $('#datetimepicker1').datetimepicker();
 });

The imports on the same page:同一页面上的导入:

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.0/moment-with-locales.js"></script>
<script src="https://rawgit.com/tempusdominus/bootstrap-4/master/build/js/tempusdominus-bootstrap-4.min.js"></script>
<link href="https://rawgit.com/tempusdominus/bootstrap-4/master/build/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

When clicking on the button to select a date and time the current date and time is set:当点击 select 按钮时,当前日期和时间设置为:

在此处输入图像描述

If this is set the value is this when I submit:如果设置了这个值,我提交时是这个值:

01/01/0001 00:00:00 

As i said in the comments, the datepicker sees the second digits as month, so you should set a custom format like so正如我在评论中所说,日期选择器将第二个数字视为月份,因此您应该像这样设置自定义格式

$('#datetimepicker1').datetimepicker({
    format: 'MM/DD/YYYY HH:mm:ss',
    date: moment() //So the picker starts from now instead of the default date
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过iso&#39;&#39;0001-01-01T01:00:00&#39;创建日期,添加16秒 - Creating Date by iso ''0001-01-01T01:00:00' adding 16 second 将日期从javascript传递到json http post方法的格式已更改为0001-01-01T00:00:00 - Passing date from javascript to json http post method format changed to 0001-01-01T00:00:00 获取格式为2016-01-01T00:00:00.000-00:00的日期 - Get date in format 2016-01-01T00:00:00.000-00:00 将&#39;0001-01-01T00:00:00&#39;UTC转换为GMT + 1会增加58分45秒 - Converting '0001-01-01T00:00:00' UTC to GMT+1 is adding 58 minutes 45 seconds 获取昨天的日期并将时间设置为 01:30:00 - Get yesterday's date and set time to 01:30:00 创建小时数数组:00:00、01:00、02:00 - Create array of hours: 00:00, 01:00, 02:00 为什么 new Date(null) 返回这个:Date 1970-01-01T00:00:00.000Z? - Why new Date(null) is returning this: Date 1970-01-01T00:00:00.000Z? 如何使用 JavaScript 将我的日期“2020 年 1 月 1 日星期三 00:00:00 GMT+0530(印度标准时间)”转换为 2020 年 1 月 1 日? - How can I convert my date “Wed Jan 01 2020 00:00:00 GMT+0530 (India Standard Time) ” to JAN 01,2020 using JavaScript? javascript排除“ 00”和“ 01”字符串 - javascript exclude “00” and “01” strings 倒计时在01:00被卡住 - Countdown gets stuck at 01:00
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM