I'm trying to migrate some data from MySQL DateTime format. Here's one:
$old_date = "2019-05-06 08:00:00"
My content type has a custom field using DateTime.
Using the info from SO links below, I can do this:
$date_object = DateTime::createFromFormat("Y-m-d H:i:s", $old_date);
which gives me a lovely object in my current timezone.
date: 2019-05-06 09:00:00.0 US/Central (-05:00)
MySQL is looking for a string in the UTC format. When I attempt to format this new object, it dutifully returns
But this is not helpful. Using the Drupal 8.7 admin interface, when I enter the date and time values, I see in MySQL table when I save the node, that I get:
So, apparently Drupal Entity has a handler to automatically instantiate a localized DateTime value in MySQL that is UTC friendly. I ask because I haven't found what this method might be and I have not found it in DrupalDateTime or related classes. Happy to be shown what I've overlooked. Or how to discern how Entity handles all of these functions that I can use in my custom modules.
Or should I do the math for each of these strings and hope I get the correct timezone differential depending on the time of the year?