Dealing with GMT being spat out by a cURL/datetime in PHP

Soldato
Joined
27 Dec 2005
Posts
17,296
Location
Bristol
I'm building a page for myself to gather and display API data from my energy provider. All good so far, cURL working and json_decode looking good and now just need to format the data.

Problem is the datetimes given are in GMT. I've tried sticking...

Code:
date_default_timezone_set('Europe/London');


...at the top, and...

Code:
$arr = json_decode($response, true);
foreach ($arr['results'] as $row){
$datetime = $row['valid_from'];
$datetime = new DateTime($datetime, new DateTimeZone('GMT'));


...further down, but no difference. Even changing it to Europe/Berlin or something makes no difference. So what's the best practice way of changing the timezone of the array?

Their documentation simply states:

Datetimes

Some API end-points accept datetime strings as parameters. These should be passed in ISO 8601 format. Eg: "2018-05-17T16:00:00Z"

We strongly recommend that timezone information is included on all datetime parameters. If no timezone information is included, the “Europe/London” timezone will be assumed and results may vary between GMT and British Summer Time.
 
Back
Top Bottom