We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to display Local Times in Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

146758 Aug 18,2019 08:16 AM UTC Aug 21,2019 05:19 AM UTC JavaScript - EJ 2 5
loading
Tags: Grid
Craig Champion
Asked On August 18, 2019 08:16 AM UTC

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


Manivel Sellamuthu [Syncfusion]
Replied On 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 
 


Craig Champion
Replied On 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


Manivel Sellamuthu [Syncfusion]
Replied On 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 


Craig Champion
Replied On August 20, 2019 12:10 PM UTC

That resolves the issue. Thanks

Manivel Sellamuthu [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon