5

正如在DateTimePicker / Basic usage中可以看到的那样,我在下面使用的示例将当前时间设置为 12:00 AM,而不是 DateTime.Now,当按下 DateTimePicker 页脚处的链接时。如何解决?

@(Html.Kendo().DateTimePickerFor(m => m.VisitDate)
    .Animation(true)
    .Format("dd/MM/yyyy HH:mm")
    .TimeFormat("HH:mm")
    .Min(new DateTime(1900, 1, 1)) 
    .Max(new DateTime(2099, 12, 31)) 
    .Footer(true)
    .Value(DateTime.Now) 
)

之前: 之后:
前

后

链接插入午夜 - 但这感觉不对。

你如何让它插入当前时间呢?


更新:这是我在最后一步使用的 DateTimePicker 和 javascript 方法:

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var today = DateTime.Now.ToString("dd/MM/yyyy 00:00", 
                    new System.Globalization.CultureInfo("en-US"));
}


@(Html.Kendo().DateTimePicker()
    .Name("datetimer")
    .Animation(true)
    //.Culture("en-US")
    .TimeFormat("HH:mm")
    .Min(new DateTime(1900, 1, 1)) 
    .Max(new DateTime(2099, 12, 31)) 
    .Value(DateTime.Now)
    .Format("dd/MM/yyyy HH:mm")
    .Events(e => e.Change("datetimepicker_change"))
)


<script>
function datetimepicker_change() {
    // I use this method so that when selecting another day except from today, 
    // the hour should be 00:00. But it does not make sense whether or not using it 
    if ($('#datetimer').val() != '@today') {
        return;
    }


    if ($('#datetimer').val() == '@today') {
        $('#datetimer').val('@DateTime.Now.ToString("dd/MM/yyyy HH:mm")');
    }
}
</script>
4

1 回答 1

4

你好,我就是这样处理的;

var today = DateTime.Now.ToString("dd/MM/yyyy 00:00", new System.Globalization.CultureInfo("en-US"));

@(Html.Kendo().DateTimePicker()
    .Name("test")
    .Animation(true)
    .TimeFormat("HH:mm")
    .Min(new DateTime(1900, 1, 1))
    .Max(new DateTime(2099, 12, 31))
    .Value(DateTime.Now)
    .Format("dd/MM/yyyy HH:mm")
    .Events(e => e.Change("datetimepicker_change"))
 )

 <script>
  function datetimepicker_change() {
    if ($('#test').val() == '@today') {
        $('#test').val('@DateTime.Now');
    }
  }
 </script>

完整代码通过 VS 2015

结果:youtube

于 2015-12-21T16:03:55.290 回答