1

I created a custom module to update news and stories to magento 2 website.I have the date field in my form( main.php ).

 $dateFormat = $this->_localeDate->getDateFormat(
        \IntlDateFormatter::MEDIUM
    );
 $timeFormat = $this->_localeDate->getTimeFormat(
        \IntlDateFormatter::MEDIUM
    );

 $fieldset->addField(
        'news_date',
        'date',
        [
            'name' => 'news_date',
            'label' => __('News date'),
            'title' => __('News date'),
            'date_format' => $dateFormat,
            //'time_format' => $timeFormat,
            'required' => true,
            'disabled' => $isElementDisabled
        ]
    );

My grid file is like below.

this->addColumn(
        'news_date',
        [
            'header' => __('News date'),
            'index' => 'news_date',
            'type'      => 'date',
        ]
    );

What my issue is actual saved date is not showing in grid.if i save the news for Oct 29, 2019 grid will show Oct 28, 2019. Below attached two images.

form enter image description here

Grid enter image description here

What is the issue behind this? Can anyone please help me?

1

This happening because of Time Zone Problem:

Go to Configuration > General > locale Options > Time Zone

Set the Server time zone and Magento Time zone same for this Problem.

Hope this will help You!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.