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

DateTime Formatting

6 Answers 147 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Ashleigh L
Top achievements
Rank 1
Ashleigh L asked on 13 May 2015, 06:05 PM

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

Sort by
0
Plamen
Telerik team
answered on 14 May 2015, 06:18 AM
Hi,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ashleigh L
Top achievements
Rank 1
answered on 14 May 2015, 06:45 PM

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.

0
Plamen
Telerik team
answered on 15 May 2015, 05:26 AM
Hi,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ashleigh L
Top achievements
Rank 1
answered on 15 May 2015, 03:08 PM
That worked, thanks Plamen.
0
Ashleigh L
Top achievements
Rank 1
answered on 15 May 2015, 03:08 PM
That worked, thanks Plamen.
0
Ashleigh L
Top achievements
Rank 1
answered on 15 May 2015, 03:08 PM
That worked, thanks Plamen.
Tags
Templates
Asked by
Ashleigh L
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Ashleigh L
Top achievements
Rank 1
Share this question
or