I had this issue and wand to share it in case others stumble across the the same situation.
In one of my models, I stored a default datetime in addFields():
['created_date', 'type' => 'datetime', 'default' => date('Y-m-d H:i:s', time())],
When I loaded this value, the time was not correct but 1 hour ahead, e.g. 20:00:00 turned into 21:00:00.
I am in UTC+1 timezone, so it was obvious the problem must be associated with this. After some searching, I found that:
- ATK uses UTC as standard for timezones unless set differently
- but the time() uses my local timezone.
So my local time was interpreted as UTC, and hence when loading it the 1 hour difference was added to it.
The easiest solution I found was to add the timezone explicitly to ATK:
['created_date', 'type' => 'datetime', 'default' => date('Y-m-d H:i:s', time()), 'persist_timezone' => 'Europe/Berlin'],
Just for you to keep in mind that ATK and PHP will use different timezones when youre outside UTC and timezone is not explicitly set.