最近入住的朋友有时间

时间:2014-01-13 18:06:39

标签: api geolocation foursquare checkin

我正在使用/checkins/recent端点。我正试着赶上办理登机手续的时间。我找到了一个json对象createdAt。那与时间有​​关吗?

enter image description here

所以,我的问题是如何从最近的签到中获得时间。

1 个答案:

答案 0 :(得分:2)

Foursquare API docs for checkin object清楚地表明createdAt表示生成对象时的unix纪元时间(活动时间)。因此,您可以从纪元获得UTC时间。添加时区偏移量,它表示您需要在获取当地时间的时间内添加的分钟数。例如,您的问题中的示例checkin对象来自孟加拉国,因此其偏移量为360.
你没有提到语言,但是从你的标签列表中,我假设你已经使用了Ruby,所以在ruby中这样做的一个简单方法就是。

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

要获取当地时间,您可以使用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

您可以使用格式化方法将对象格式化为所需的值。