
I'm trying to use a single datetime field from my JSON to fill the date and time in separate areas of my template, and it's not working.
Here's an example of the JSON:
{
"Course"
: {
"Name"
:
"Test Course"
,
"ChapterData"
:[{
"Name"
:
"Module 1"
,
"TaskData"
:[{
"Name"
:
"Module 1 Task 1"
,
"CompletedDate"
:
"05\/12\/2015 19:25:43"
}]
}]
}}
And here's where I'm trying to format and display the information:
<
i
class
=
"fa-icon-check mar-rt-sm"
></
i
>#= kendo.toString(data.ChapterData[c].TaskData[t].CompletedDate, 'dd-MMM-yyyy') #
<
span
class
=
"hidden-xs"
>#= kendo.toString(data.ChapterData[c].TaskData[t].CompletedDate, 'h:mm tt') #</
span
>
Instead of seeing "12-May-2015" for the date and "7:25 PM" for the time, I'm seeing the full datetime string, completely unformatted, in both areas (ie. 05/12/2015 19:25:43). I tried modifying the JSON to pass back separate date and time fields and that didn't work either.
6 Answers, 1 is accepted
You are actually passing sting so you will have to turn it to Data before you as it is explained in this help topic and then use the toString() method. Here is the code that worked at my side.
Regards,
Plamen
Telerik

Thanks Plamen, two questions though. I have date (no time) fields in other locations on this page, and just using kendo.toString() worked fine there - any ideas why?
Second, while your code example works for the date, it is always returning 12:00 AM when trying to format it for time. I've modified the example you provided, but I'm not sure how to save it, so here's the change I made:
console.log(kendo.toString(kendo.parseDate(
"05\/12\/2015 19:25:43"
),
'hh:mm tt'
));
No matter the time provided, 12:00 AM is always returned.
In such case you need to use specific format to recognize the specific time. Here is the updated page that worked at my side.
Regards,
Plamen
Telerik


