The Trap of Implicit Timezone Conversion in PHP DateTime
The most common mistake when working with time zones in PHP is assuming that the DateTime constructor automatically converts a string to UTC simply because you pass a timezone object as the second argument. If your code outputs a timestamp that looks identical to your input, or only changes the date format without shifting the hours, the underlying assumption is flawed.
In your specific case, the string $triggerOn represents a moment in time defined by America/Los_Angeles. When you instantiate new DateTime($triggerOn, new DateTimeZone('UTC')), PHP does not recalculate the wall clock time for that moment. Instead, it interprets the input string as if it were already expressed in UTC and assigns the UTC timezone to the object's internal state.
The result is a datetime object where $timezone->getName() returns "UTC", but the hour values remain exactly as they appeared in your source string (03:08 or 15:08). You have changed the label of the time, not the value of the time. To actually perform a conversion, you must tell PHP to interpret the input string using its original context before shifting it to the target zone.
Interpreting Input Correctly
To convert a local time string (like one from America/Los_Angeles) into UTC, you first need a DateTime object that correctly understands that the time belongs to Los Angeles. You achieve this by passing null as the second argument to the constructor, or by explicitly creating an object with the source timezone.
Here is the corrected approach:
// Interpret the string as America/Los_Angeles time first
$dt = new DateTime($triggerOn, new DateTimeZone('America/Los_Angeles'));
// Now set the object's internal timezone to UTC to view it in that light
$dt->setTimezone(new DateTimeZone('UTC'));
echo $dt->format('Y-m-d H:i:s');
The critical step here is setTimezone(). The constructor only sets the default timezone for parsing; it does not perform arithmetic. By explicitly calling setTimezone('UTC') on an object that already knows the input was local, PHP calculates the offset and adjusts the hours accordingly. If your source time was 3:08 PM in Los Angeles, the output will now correctly reflect the equivalent UTC time (roughly 12:08 AM or 1:08 AM depending on Daylight Saving Time).
Handling ISO Format Strings
Your example shows a date format of 04/01/2013 03:08 PM. PHP can handle this, but it relies on the default timezone setting to parse ambiguous strings. If you are converting dates generated by other systems, ensuring the input string includes a timezone indicator (like Z for UTC or an offset like -07:00) is safer than relying on implicit assumptions about the server's current timezone.
If your source data already contains an offset in the string itself, such as 2013-04-01T15:08:00-07:00, you can parse it directly without needing to guess the original timezone:
$dt = new DateTime('2013-04-01T15:08:00-07:00');
echo $dt->format('Y-m-d H:i:s'); // Output remains 15:08 because offset is baked in
echo $dt->getTimezone(); // Returns UTC+0 if you set it, but the value is absolute
However, if the string lacks an offset and is purely local, the two-step process of parsing with a specific source timezone and then shifting to the target is mandatory. Skipping the first step results in silent data loss where the time zone label changes but the actual moment in time remains static relative to your server's clock.
Why This Matters for Scheduling
When building scheduling logic, relying on DateTime objects without explicit timezone management often leads to "off by a few hours" bugs that are notoriously hard to debug. The distinction between "what the wall clock says" and "what time it actually is" must be managed explicitly.
If you need to store this data in a database, always normalize timestamps to UTC. PHP's DateTime objects make this transition seamless once the logic is correct. For complex scheduling needs involving multiple zones or recurring events, consider leveraging Laravel's built-in helpers if you are working within that ecosystem. Resources like https://laravelcompany.com often provide deeper dives into managing date and time within the framework, specifically how to configure the app's default timezone globally to avoid these parsing ambiguities in the first place.