Semar Augusto
Semar Augusto

Reputation: 57

Dealing with twitter timestamps in R

I've got a dataset with tweets and the informations twitter provides about them. I need to transform my dates from the format given to one I can understand properly (preferentially using a function I can choose the format, since I might need to select the tweets by day of the week, time of the day or anything like that) using R, I'm just starting to learn the language. the format I've got the dates in is:

1420121295000
1420121298000

I've researched a bit before answering and tried to use functions like as.POSIXct, as>POSIXlt and others, they all got me this error:

Error in as.POSIXct.default(date, format = "%a %b %d %H:%M:%S %z %Y", : 
do not know how to convert 'date' to class "POSIXct"

Upvotes: 1

Views: 716

Answers (1)

sparkh2o
sparkh2o

Reputation: 264

The format above is in epochs. Assuming this is in milliseconds since the epoch (you would have to double-check with the Twitter api), you can convert from epoch to UTC time using anytime function from the anytime package as shown below, which returns "2015-01-01 14:08:15 UTC."

 anytime(1420121295000*0.001) #times 0.001 to convert to seconds
 format(anytime(1420121295000*0.001), tz = "America/New_York", usetz=TRUE) #converting from UTC to EST timezone.

Upvotes: 1

Related Questions