kendo-uidatetimepicker

Set the format of a Kendo DateTimePicker date sent to the controller


I'm using a Kendo DateTimePicker in my application.

The value I get from it in my application is

Wed Aug 13 2014 00:00:00 GMT+0200 (Romance Daylight Time)

I can't parse this to a DateTime. I get a "String was not recognized as a valid DateTime." error.

How can I set the format of the date I get from the DateTimePicker?? Is there an option in Kendo DateTimePicker??t


Solution

  • If you Need to Change the Date that you get from your application you can do as below

    var dateobj=kendo.parseDate("Wed Aug 13 2014 00:00:00 GMT+0200 (Romance Daylight Time)", "yyyy-MM-dd h:mm:ss tt");
    var datestring = kendo.toString(dateobj, "MM-dd-yyyy h:mm:ss tt");
    

    kendo.parseDate() will Parse the Date to a Date Object and kendo.toString() will format the date to a string

    If you need to convert the date you get from the Datepicker Do this

    var datepicker = $("#datepicker").data("kendoDatePicker");
    var value = datepicker.value();
    kendo.toString(value,"dd/MM/YYYY")
    

    IF you need to convert Datepicker date to the Sever Date

    var datepicker = $("#datepicker").data("kendoDatePicker");
        var value = datepicker.value();
        value.toUTCString();