Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 519
Rui Martins Avatar asked Aug 13 '14 12:08

Rui Martins


People also ask

How do I change the date format on Kendo DatePicker?

You can control the format of the DatePicker by using the format property. The component can be configured either to display a single format at all times, or to display the value in different formats when the input is focused or blurred.

How do I change the default value in kendo DatePicker?

Setting the Default Value To set the initial value that is rendered by the DatePicker, set the defaultValue property.

What is format in DatePicker?

By default, the date format of the jQuery UI Datepicker is the US format mm/dd/yy, but we can set it to a custom display format, eg: for European dates dd-mm-yyyy and so on. The solution is to use the date picker dateFormat option.

What is Kendo DatePicker?

The Kendo UI for Angular DatePicker combines the Kendo UI DateInput and Calendar components. It enables the user to enter or pick a date value. The DatePicker Component is part of Kendo UI for Angular, a professional grade UI library with 100+ components for building modern and feature-rich applications.


2 Answers

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();
like image 141
cwishva Avatar answered Sep 22 '22 22:09

cwishva


Here what I have used:

 var dateobj = kendo.parseDate("Wed Aug 13 2014 00:00:00 GMT+0200 (Romance Daylight Time)");
 var datestring = kendo.toString(dateobj, "MM-dd-yyyy h:mm:ss tt");
like image 35
Stefano Magistri Avatar answered Sep 23 '22 22:09

Stefano Magistri