Reputation: 8729
I'm using /checkins/recent
endpoint. I was trying to get the check-in time. I find a json object createdAt
. is that related with time ?
So, my question is how can I get the time from recent check-ins.
Upvotes: 0
Views: 100
Reputation: 1072
The Foursquare API docs for checkin object clearly state that createdAt represents the unix epoch time when the object was generated(time of activity). So, you can get the UTC time from the epoch. Add in the time zone offset, it denotes the minutes you need to add in the time to get local time.For example, the example checkin object in your question is from Bangladesh, so it has a offset of 360.
You haven't mentioned the language but from your tag list, I am assuming you have used Ruby so a simple way to do this in ruby would be.
require 'date'
Time.at(your_createdAt_value).utc.to_datetime
#For example from your created at value
Time.at(1389630660).utc.to_datetime
#This will make a datetime object of value 2014-01-13T16:31:00+00:00
For getting local time you can use the value of timeZoneOffset.
#To get local time add in the timeZoneOffSet
Time.at(your_createdAt_value).utc.to_datetime+Rational(timeZoneOffset_value,1440)
#The 1440 value is the number of minutes in a day. Rational calculates
#the fraction of the day by using the two values and adds it to the datetime object.
#for example,
Time.at(1389630660).utc.to_datetime+Rational(360,1440)
#This will make a datetime object of value 2014-01-13T22:31:00+00:00
You can format the object to the value you want by using formatting methods.
Upvotes: 2