In this post we will look into, the way to format DateTime type columns of OData feed as string in Kendo UI Template.
For DateTime type of columns, OData returns number of seconds from January 1, 1970. Most likely you will be getting returned value as below,
Obviously you need to format returned date before displaying. You can format that using
See demo of kendo.toString() on jsfiddle
StartTime: #= kendo.toString( new Date( new Date( parseInt(returnedTimeValue.ToTime.replace("/Date(", "").replace(")/", ""), 10))),"g")#
You will get date formatted as following.
Explanation of code
Now let us examine that what exactly we are doing in above snippet. There are five steps being performed
- First replacing /Date( from returned value with empty string
- Next replacing )/ from returned value with empty string
- Parsing remaining returned value as integer
- Creating date using returned parsed integer
- Passing created date to kendo.string to format as desired.
In this way you can format a ODATA DateTime column using kendo.string. I hope you find this post useful.