- Home
- Forum
- JavaScript - EJ 2
- How to display Local Times in Grid
How to display Local Times in Grid
Hi,
We are currently displaying and formatting times in the Grid as follows:
{
field: 'DateFrom',
headerText: 'Date From',
editType: 'datetimepickeredit',
format: { type: 'dateTime', format: 'dd/MM/yyyy HH:mm:ss' },
validationRules: { required: true },
defaultValue: new Date(),
allowEditing: false,
width: 125
},
However, the backend system records and reports all dateTime as UTC as time may be recorded from multiple time zones.
I want to be able to display the DateTime in the Grid in Local Time, not the UTC.
How can specify the cell to convert the datetime returned in UTC to display in local time?
Thanks
Craig
SIGN IN To post a reply.
5 Replies
MS
Manivel Sellamuthu
Syncfusion Team
August 19, 2019 12:09 PM UTC
Hi Craig,
Thanks for contacting us.
You can achieve your requirement by using serverTimezoneOffset property of the DataUtil class as the below way.
Please find the below code example and sample for more information.
|
Index.ts
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
import { Grid, Selection } from '@syncfusion/ej2-grids';
import { Query, DataManager,DataUtil } from '@syncfusion/ej2-data';
import { orderData } from './data-source';
Grid.Inject(Selection);
/**
* Default Grid sample
*/
DataUtil.serverTimezoneOffset = new Date().getTimezoneOffset()/60;
let data: Object = new DataManager(orderData as JSON[]).executeLocal(new Query().take(15));
let grid: Grid = new Grid(
{
dataSource: data,
columns: [
{ field: 'OrderID', headerText: 'Order ID', width: 120, textAlign: 'Right' },
{ field: 'CustomerName', headerText: 'Customer Name', width: 150 },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: { type: 'dateTime', format: 'dd/MM/yyyy HH:mm:ss' }, textAlign: 'Right' },
{ field: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }
]
});
grid.appendTo('#Grid');
|
Please get back to us, if you need further assistance.
Regards,
Manivel
CC
Craig Champion
August 19, 2019 12:49 PM UTC
Hi,
The code example given makes no difference.
See: http://www.youtube.com/watch?v=Aq8ES_gOq5I - Here I am changing the offset but the times remain the same
Please advise?
Craig
MS
Manivel Sellamuthu
Syncfusion Team
August 20, 2019 10:20 AM UTC
Hi Craig,
Sorry for the inconvenience caused.
The serverTimezoneOffset property will work only for remote data. Please find the below modified sample in which grid dataSource has been consumed from remote server. In that sample you can change the serverTimeZoneOffset and see the difference.
|
Index.ts
DataUtil.serverTimezoneOffset = new Date().getTimezoneOffset()/60;
let hostUrl: string = 'https://ej2services.syncfusion.com/production/web-services/';
let data: Object = new DataManager({
url: hostUrl + 'api/Orders',
adaptor: new WebApiAdaptor ,
crossDomain: true
});
let grid: Grid = new Grid(
{
dataSource: data,
allowPaging: true,
columns: [
{ field: 'OrderID', headerText: 'Order ID', width: 130, textAlign: 'Right' },
{ field: 'CustomerID', headerText: 'Customer ID', width: 170 },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: { type: 'dateTime', format: 'dd/MM/yyyy HH:mm:ss' }, textAlign: 'Right' },
{ field: 'Freight', headerText: 'Freight', width: 160, textAlign: 'Right', format: 'C2' },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150, textAlign: 'Center' },
],
pageSettings: { pageCount: 3 }
});
grid.appendTo('#Grid'); |
Please get back to us, if you need further assistance.
Regards,
Manivel
CC
Craig Champion
August 20, 2019 12:10 PM UTC
That resolves the issue. Thanks
MS
Manivel Sellamuthu
Syncfusion Team
August 21, 2019 05:19 AM UTC
Hi Craig,
Thanks for your update.
We are happy to hear that your issue has been resolved.
Please get back to us, if you need further assistance.
Regards,
Manivel
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
CC Craig Champion
- Aug 18, 2019 08:16 AM UTC
- Aug 21, 2019 05:19 AM UTC