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

Formatting a DateTimeOffset

3 Answers 1755 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Garee
Top achievements
Rank 2
Garee asked on 07 Jun 2019, 03:01 PM

Hi,

I have some values that are DateTimeOffsets. I'm having trouble formatting them in a grid though.

This code:

columns.Bound(c => c.StartTimestamp).Width(750).Format("{0:dd/MM/yyyy HH:mm:ss}");

produces:

2019-06-06T17:47:52.0256922+01:00

when what I want to see is:

06/06/2019 17:47:52

Is the Grid unable to format DateTimeOffsets, or am I missing something?

Thanks,

Gary

3 Answers, 1 is accepted

Sort by
0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 12 Jun 2019, 10:45 AM
Hello, Gary,

The DateTimeOffset does not get serialized to a type date in the data source schema model, therefore the format will not take effect. You can use a ClientTemplate instead:

columns.Bound(c => c.StartTimestamp).Width(750)..ClientTemplate("#=kendo.toString(kendo.parseDate(StartTimestamp), 'dd/MM/yyyy HH:mm:ss')#");

https://docs.telerik.com/kendo-ui/globalization/intl/dateparsing

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Garee
Top achievements
Rank 2
answered on 12 Jun 2019, 11:39 AM

Thanks Alex - that's perfect.

Thanks also for the links to the documentation on this - that's what I was struggling to find.

Cheers,

Gary

0
Alex Hajigeorgieva
Telerik team
answered on 30 Dec 2019, 02:18 PM

Hi, Gary,

There is another way that the same can be achieved so I wanted to update the thread.

One can trick the grid that the DateTimeOffset field is a DateTime field by setting its type in the DataSource Schema Model. Then the Format will work and the ClientTemplate will become redundant:

 .Model(model =>
{
      model.Field("StartTimestamp", typeof(DateTime));
 })

columns.Bound(c => c.StartTimestamp).Format("{0:dd/MM/yyyy HH:mm:ss}");

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Grid
Asked by
Garee
Top achievements
Rank 2
Answers by
Alex Hajigeorgieva
Telerik team
Garee
Top achievements
Rank 2
Share this question
or