Timezone of Instagram medias

5.1k views Asked by At

The Instagram API return a created_time field attached to each media (example of API response here).

The value of this field is a simple timestamp. My question is : In which timezone is it ? I need this information to convert the timezone in Europe/Paris, if needed, before store it in my database (I assumed that all date related datas in my database are in Europe/Paris).

Thank you !

2

There are 2 answers

1
Stevo On BEST ANSWER

The date is in UTC so you can easily convert this to your locale. However if you want to know the local time of the place where the picture was taken then I think you would need to get the timezone from the longitude and latitude of the location attribute in the /media/search endpoint.

EDIT: This is the function I ended up creating:

function roughlyDetermineTimezoneOffset(lng, lat) {

        var sign = lat?lat<0?-1:1:0;
        return sign * lng * 24 / 360;
    }

Based upon this article: rough estimate of the time offset from GMT from latitude longitude

3
lsowen On

The field looks like the text representation of a Unix Timestamp, which is:

The number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC)

Some datetime libraries will convert that to a localtime, but the exact behavior will be determined by your programming language and datetime libary.

Just as a side note, it is generally considered best practice to store datetimes in your database in UTC, and only convert to a local datetime for presentation to a user. See https://stackoverflow.com/a/2532962/3108853 for more discussion.