Kendo DateTimePicker 设置当前小时 12:00 AM 而不是 DateTime.Now
Kendo DateTimePicker set current hour 12:00 AM instead of DateTime.Now
正如在 DateTimePicker / Basic usage 上看到的那样,我在下面使用的示例在按页脚处的 link 时将当前时间设置为 12:00 AM 而不是 DateTime.Now日期时间选择器。如何解决?
@(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)
)
之前:
之后:
link 插入午夜 - 但这感觉不对。
如何让它插入当前时间?
更新: 这是我在最后一步使用的 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>
你好,我是这样处理的;
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>
结果:youtube
正如在 DateTimePicker / Basic usage 上看到的那样,我在下面使用的示例在按页脚处的 link 时将当前时间设置为 12:00 AM 而不是 DateTime.Now日期时间选择器。如何解决?
@(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)
)
之前:
之后:
link 插入午夜 - 但这感觉不对。
如何让它插入当前时间?
更新: 这是我在最后一步使用的 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>
你好,我是这样处理的;
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>
结果:youtube