Skip to main content
65 votes
Accepted

My magento 2 website is crashed: Unknown or bad timezone () error

I don't know exactly HOW it happened, but in my scenario the core_config_data table was corrupted. It had added a new row somehow with path set to general and value set to NULL: This caused Magento\...
Giel Berkers's user avatar
  • 12.3k
11 votes
Accepted

magento 2 - getCreatedAt() returns UTC time and not local time

You can use an instance of Timezone to convert it into store's timezone. Here is a very generic example. namespace VendorName\ModuleName\MyDir; class MyClass { private $timezone; public ...
Maruti N. Sharma's user avatar
9 votes

My magento 2 website is crashed: Unknown or bad timezone () error

The timezone should be one of the List of Supported Timezones. Seems that you are using empty timezone. Try to detect the current store timezone using the next query: SELECT * FROM `core_config_data`...
Siarhey Uchukhlebau's user avatar
9 votes

Get current date time used in magento for saving data

Keep in mi mind that PDO is aware of the timezone set in your Magento installation, which is most likely causing you troubles. When you try to work with automatic timestamps, try using Mage::getModel(...
Stjepan's user avatar
  • 184
7 votes
Accepted

Make magento 2 grid date column follow config timezone

Add class in date filed to format date according to time format. use this code. <column name="creation_time" class="Magento\Ui\Component\Listing\Columns\Date"> <argument name="data" ...
Rakesh Varma's user avatar
  • 2,226
5 votes

Convert datetime and timezone to datetime in Magento 2

Try This protected $timezone; public function __construct( \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone, ...... ) { $this->timezone = $timezone; } $dateTimeZone = $this-&...
Sanjay Gohil's user avatar
  • 2,200
4 votes

Get current date time used in magento for saving data

use the following function. It will auto calculate the time according to the timezone saved in admin Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s') Store this data in db
Vivek Khandelwal's user avatar
4 votes

Convert datetime and timezone to datetime in Magento 2

1) We can use the PHP basic: http://php.net/manual/en/datetime.settimezone.php <?php $datetime = new DateTime('2017-01-20T13:59:19+03:00', new DateTimeZone('Europe/London')); $datetime->...
Khoa TruongDinh's user avatar
4 votes
Accepted

Database dates get stored in local timezone

Try this one to check the actual date and time as it is configured in your Magento $time = Mage::getModel('core/date')->timestamp(time()); $now = date('Y-m-d h:i:s', $time); echo $now;
PЯINCƎ's user avatar
  • 11.7k
4 votes

Magento2 convert UTC time to IST

Yes you can set timezone from admin panel. Go to Store->configuration->Genral You will find time zone according to your store you can set timezone.
Shubham Khandelwal's user avatar
4 votes
Accepted

Magento 2 - Admin grid and export use different timezone

I've found an answer for this problem. Please do comment if there's anything wrong about this answer. Basically we have to add metadataprovider configuration in [ModuleName]/etc/adminhtml/di.xml ...
user7414328's user avatar
3 votes

Magento 2 Data Migration time difference?

If your Magento 1 server has the time zone set to anything other than UTC, you must configure the offset to migrate timestamp fields. To transform time to a different time zone, use the Data Migration ...
Sangeeta Chandaliya's user avatar
3 votes
Accepted

Magento2 not getting current time

$objDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\Timezone'); $currentTime = $objDate->formatDatetime(date("Y-m-d H:i:s")); $currentTimestamp = strtotime($objDate->...
Naveenbos's user avatar
  • 1,226
3 votes
Accepted

date displays wrong

Times are store in the database as UTC (+0:00). When you use the $date object to render a date, it gets translated into your store's configured timezone. For example, if the date is 2017-02-15 14:37:...
Brett's user avatar
  • 1,854
3 votes

Convert datetime and timezone to datetime in Magento 2

This one works for me \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone $this->timezone = $timezone $localizedDateTimeISO = $this->timezone->date(new \DateTime($repliedAt))->...
Hiren Soni's user avatar
3 votes

Get current Date and time on frontend

It's 2 general ways: // current time or any time in UTC $now = new \DateTime('now', new \DateTimeZone('UTC')); // instances $timezone = \Magento\Framework\App\ObjectManager::getInstance() ->...
Victor Tihonchuk's user avatar
2 votes

Convert datetime and timezone to datetime in Magento 2

instantiate protected $_date; public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $date) { $this->_date = $date; } and use in your function $this->_date->...
Prakhar Bhardwaj's user avatar
2 votes

Convert datetime and timezone to datetime in Magento 2

$date = '2018-01-29 13:10:20'; $this->formatDate( $this->_localeDate->date(new \DateTime($date)), \IntlDateFormatter::MEDIUM, ...
Jarik Bulba's user avatar
2 votes

Get current date time used in magento for saving data

<?php require_once 'app/Mage.php'; Mage::app(); //Magento's timestamp function makes a usage of timezone and converts it to timestamp $currentTimestamp = Mage::getModel('core/date')->timestamp(...
Peter's user avatar
  • 21
2 votes

Get current Date and time on frontend

Use below code. use Magento\Framework\Stdlib\DateTime\TimezoneInterface; class Yourclass extends AbstractClass { protected $timezoneInterface; public function __construct( ... ...
S.P's user avatar
  • 1,554
1 vote
Accepted

M2 | How to configure store's timezone to set date as I am getting wrong date in magento?

I got the right time as per my clock from magento as below: ->Configured Timezone from Magento Backend Stores -> Configuration -> General ->Locale Options -> Timezone to reflect "Gulf Standard ...
Ajwad Syed's user avatar
  • 1,591
1 vote

How to add/subtract month to/from date in Magento2?

You should try : $date = $this->date->gmtDate('Y-m-d\TH:i:s\Z', strtotime('+1 month'));
Vinz's user avatar
  • 995
1 vote

order time difference from magento 1 to magento 2 after migration

Please check your MySQL server timezone. What happens usually is your MySQL server might be set to UTC timezone hence time in database is considered as UTC, now as you have set Magento Timezone to ...
Abdul Pathan's user avatar
  • 2,812
1 vote

Magento2: Order updated_at stored in DB in timezone CEST but delivered/transformed to UTC by $order->getUpdatedAt in Environment "crontab"

after hours of debugging we found the issue. MySQL and server configured timezone is CEST. So all native queries done by PHP or direct mysql shows date in configured timezone CEST. All application ...
sbothner_y1's user avatar
1 vote
Accepted

Fatal error: Call to a member function getConfigTimezone() on null Magento 2.2

you should use __construct instead _construct. I see that you have one underline. Fix it and should be fine
K. Maliszewski's user avatar
1 vote

How to get client(user) browser timezone in magento 2?

You can do this in plain Javascript: var myDate = new Date(); document.write(myDate.getTimezoneOffset()); More info here: http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-...
Niels's user avatar
  • 1,416
1 vote

date displays wrong

You can try below code to convert the date into your desired format: $currentDate = Mage::getModel('core/date')->date('d-m-Y', strtotime($_item->getCreatedTime())); Also FYI, Since Magento is meant ...
Aman Agarwal's user avatar
1 vote

Convert datetime and timezone to datetime in Magento 2

You can easily get Current Store Date Time by injecting in your class constructor in instance of \Magento\Framework\Stdlib\DateTime\TimezoneInterface and use that one to get the DateObject. For ...
Mr. Lewis's user avatar
  • 1,931
1 vote

Convert datetime and timezone to datetime in Magento 2

Try this: $timezoneInterface = new \Magento\Framework\Stdlib\DateTime\TimezoneInterface; $dateTimeZone = $timezoneInterface->date($yourDate)->format('m/d/y H:i:s');
Fran Mayers's user avatar
  • 2,803
1 vote

My magento 2 website is crashed: Unknown or bad timezone () error

I solved the problem with the correct answer; 1,Select TO: select * FROM `core_config_data` WHERE path = 'general' 2,Delete TO: DELETE FROM `core_config_data` WHERE path = 'general' Then the ...
jerry xu's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible