2014-01-13 23 views
0

我正在使用/checkins/recent終點。我正在嘗試辦理登機手續。我找到了一個json對象createdAt。與時間有關嗎?獲取朋友最近簽到的時間

enter image description here

所以,我的問題是我怎麼可以從近期簽入的時間。

+0

foursquare API文檔(https://developer.foursquare.com/docs/responses/checkin)明確指出createdAt表示生成對象(活動時間)時的unix時代。所以,你可以從時代獲得UTC時間。添加時區偏移量,它表示您需要在獲得本地時間時添加的分鐘數。對於孟加拉國,它與json中的相同。你使用哪種語言?幾乎所有的語言都有從unix時代轉換時間的標準方法。 – erosenin

+0

添加這個答案。 – erosenin

回答

2

Foursquare API docs for checkin object明確指出createdAt表示生成對象(活動時間)時的unix時期。所以,你可以從時代獲得UTC時間。添加時區偏移量,它表示在獲取本地時間時需要添加的分鐘數。例如,問題中的示例檢入對象來自孟加拉國,因此其偏移量爲360.
您沒有「提到的語言,但從你的標籤列表,我假設你已經使用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 

您可以使用格式化方法將對象格式化爲所需的值。