This is a migrated thread and some comments may be shown as answers.

Format / ParseFormats doesn't work

2 Answers 204 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Tegu
Top achievements
Rank 1
Tegu asked on 08 Aug 2018, 10:07 PM

Hello,

I am using a Kendo DateTimePicker in an ASP.Net Core 2 project. The DateTimePicker shows the date properly just in a wrong (probably default) format.

The data is coming from the controller in Json format. The server side object is simple C# DateTime.

The shown date is: http://prntscr.com/kgdnwe
The wished format is for example: yyyy/MM/dd hh:mm

The code of the DateTimePicker:

                        @(Html.Kendo().DateTimePicker()
                              .Name("tbM1Added")
                              .Format("yyyy/MM/dd hh:mm tt")
                              .ParseFormats(new string[]{ "yyyy/MM/dd", "hh:mm tt" })
                              .HtmlAttributes(new { style = "width: 100%" })
                              )

The js code:

        document.getElementsByName("tbM1Added")[0].value = selectedUser.M1Added;

When I write it on the console it shows:

Fri Oct 20 2017 23:11:50 GMT+0200 (Central European Summer Time)

Can you give me any idea how to achieve the desired datetime format? 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 09 Aug 2018, 11:27 AM
Hi Tegu,

I have examined the code and noticed that the value for the input element rendered by DateTimePicker is changed with the JavaScript. In order for the picker to work as expected you need to set the value for it using the value() method. The code for setting the value in the picker would look similar to the following.

$("#tbM1Added").getKendoDateTimePicker().value(selectedUser.M1Added);

Give this code a try and let me know how it works for you.


Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Tegu
Top achievements
Rank 1
answered on 09 Aug 2018, 07:24 PM

Yes, it is working well.

Thanks.

Tags
Date/Time Pickers
Asked by
Tegu
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Tegu
Top achievements
Rank 1
Share this question
or