Skip to content

i want to export created_at in qatar time zone

my code for converting created_at in qatar time zone works in admin grid ,i need code for exporting createad at in qatar time, i have tried didn’t get converted during export

public function __construct(
    TimezoneInterface $timezone,
    MagentoFrameworkViewElementUiComponentContextInterface $context,
    MagentoFrameworkViewElementUiComponentFactory $uiComponentFactory,
    array $components = [],
    array $data = []
) {
    $this->timezone = $timezone;
    parent::__construct($context, $uiComponentFactory, $components, $data);
}

public function prepareDataSource(array $dataSource)
{
    if (isset($dataSource['data']['items'])) {
        $fieldName = $this->getData('name');
        foreach ($dataSource['data']['items'] as &$item) {
            if (isset($item[$fieldName])) {
                // Convert time to Qatar timezone
                $gmtTime = $item[$fieldName];
                $qatarTimeZone = 'Asia/Qatar';
                $qatarTime = $this->timezone->date(new DateTime($gmtTime))
                    ->setTimezone(new DateTimeZone($qatarTimeZone))
                    ->format('Y-m-d H:i:s');
                $item[$fieldName] = $qatarTime;

            }
        }
    }
    return $dataSource;
}

}