查询日期时间选择器中的分钟格式问题

Minutes formatting issue in Query date time picker

我是 jQuery 的新手,但我已经使用 C# 编程两年多了。我正在开发一个 MVC 项目,在那里我实现了一个 jQuery 日期时间选择器,用于获取开始日期的用户输入。我以为我为此创建了正确的日期时间格式。因为它显示了我在大多数 PC 中想要的内容,例如:-“12/05/2015 12:04”。但在某些 PC 中,当分钟的值小于 10 时,它会被搞砸。它不会在分钟的最后一位数字前显示零。像这样:- '12/05/2015 12:4'。

• 这是我的 HTML 日期时间选择器代码:

{<input class="col-sm-6 col-xs-12" type="text" id="txtStart" value = '@(Model.Appointment.StartTime == null ? null : Model.Appointment.StartTime.ToString("dd/MM/yyyy HH:mm"))' disabled="disabled"  />}

• 这是我的日期时间选择器脚本:

<script type="text/javascript">    
$('#txtStart').datetimepicker({ step: 10, format: 'd/m/Y H:i' });

…
…
…
</script>

• 这是我正在使用的“日期时间选择器”资源的 link:

http://www.jqueryscript.net/time-clock/Clean-jQuery-Date-Time-Picker-Plugin-datetimepicker.html

你能给我一些建议吗?

感谢您的帮助,Kushan Randima。

您是否尝试过对日期使用秒格式:

<script type="text/javascript">    
$('#txtStart').datetimepicker({ step: 10, format: 'd/m/Y H:i:s' });

我添加了以下方法来将当前日期和时间设置为 DateTimePicker。它帮助我解决了这个问题。我做了一些技巧来获得我需要的完全相同的格式。

//Set Current Date & Time to "txtStart"     
        var currentdate = new Date();            
        var datetime = ("0" + currentdate.getDate()).slice(-2) + "/"
                    + ("0" + (currentdate.getMonth() + 1)).slice(-2) + "/"
                    + currentdate.getFullYear() + " "
        + ("0" + currentdate.getHours()).slice(-2) + ":"
        + ("0" + currentdate.getMinutes()).slice(-2);

干杯!