Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Jordan Scott
Jordan Scott
16,680 Points

How to change API JSON Date and Time (PHP).

I am using Forecast.IO weather API to pull in JSON weather data about my location (using lat/long). I cannot figure out how to change the timezone/offset to make it so the data is in the timezone of the user accessing the website.

I am using the API Wrapper Library found here: https://github.com/tobias-redmann/forecast.io-php-api

The Class: https://github.com/tobias-redmann/forecast.io-php-api/blob/master/lib/forecast.io.php

3 Answers

Andrew Shook
Andrew Shook
31,709 Points

Jordan, what time format is the data coming to you in? UTC, UNIX timestamp, or the timezone of the server Forecast.IO is hosted on? If you can figure that out you, and you know the timezone of the user, you should be able to use PHP's DateTime class to transform the time you're given to the correct timezone.

Jordan Scott
Jordan Scott
16,680 Points

It is a UNIX Timestamp. Could you send me a link to an example of something like this? Or just show me the concept?

Michael Ilichov
Michael Ilichov
528 Points

So, any suggestions about how to deal with timestamps future forecast???