Kendo DateTimePicker sets the current hour to 12:00 AM instead of DateTime.Now

As you can see from the use of DateTimePicker / Basic , the example below sets the current hour to 12:00 AM instead of DateTime. Now when you click the link on the DateTimePicker footer. How to fix it?

@(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) ) 

Before:
Before
After:

The link adds midnight - but it seems wrong.

How do you now insert the current time?


Update: Here are the DateTimePicker and javascript methods that I used in the last step:

 @{ 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> 
+6
source share
1 answer

Hello, this is how I handle this:

 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> 

full code through VS 2015

result: youtube

+4
source

All Articles