DateTime Formatting

7 posts, 0 answers
  1. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 13 May 2015 Link to this post

    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.

  2. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 14 May 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 14 May 2015 in reply to Plamen Link to this post

    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.

  5. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 15 May 2015 Link to this post

    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!
     
  6. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 15 May 2015 in reply to Plamen Link to this post

    That worked, thanks Plamen.
  7. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 15 May 2015 in reply to Plamen Link to this post

    That worked, thanks Plamen.
  8. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 15 May 2015 in reply to Ashleigh L Link to this post

    That worked, thanks Plamen.
Back to Top
Kendo UI is VS 2017 Ready