Question

I have some Twitter data I got through their GET search. The dates have the following GMT format.

Thu, 19 Jul 2012 01:32:43 +0000  
Thu, 19 Jul 2012 01:32:43 +0000  
Thu, 19 Jul 2012 01:32:40 +0000  
Thu, 19 Jul 2012 01:32:39 +0000  
Thu, 19 Jul 2012 01:32:36 +0000  
Thu, 19 Jul 2012 01:32:32 +0000  
Thu, 19 Jul 2012 01:32:28 +0000  
Thu, 19 Jul 2012 01:32:27 +0000  
Thu, 19 Jul 2012 01:32:28 +0000  
Thu, 19 Jul 2012 01:32:27 +0000  
Thu, 19 Jul 2012 01:32:18 +0000

Any idea how could I convert them to UTC format? Unix and/or R solutions would be preferable.

Update: By UTC, I mean UTC timestamp in seconds. For example: 1318394558.

Was it helpful?

Solution

With the date tool, perhaps something like:

date -f file.txt "+%Y-%m-%d %H:%M:%S %Z"

Results:

2012-07-19 11:32:43 EST
2012-07-19 11:32:43 EST
2012-07-19 11:32:40 EST
2012-07-19 11:32:39 EST
2012-07-19 11:32:36 EST
2012-07-19 11:32:32 EST
2012-07-19 11:32:28 EST
2012-07-19 11:32:27 EST
2012-07-19 11:32:28 EST
2012-07-19 11:32:27 EST
2012-07-19 11:32:18 EST

Alternatively, something like:

date -f file.txt "+%F %T"

Gives:

2012-07-19 11:32:43
2012-07-19 11:32:43
2012-07-19 11:32:40
2012-07-19 11:32:39
2012-07-19 11:32:36
2012-07-19 11:32:32
2012-07-19 11:32:28
2012-07-19 11:32:27
2012-07-19 11:32:28
2012-07-19 11:32:27
2012-07-19 11:32:18

EDIT:

date -f file.txt -u +%s

Results:

1342661563
1342661563
1342661560
1342661559
1342661556
1342661552
1342661548
1342661547
1342661548
1342661547
1342661538

HTH

OTHER TIPS

In R,

dat <- c("Thu, 19 Jul 2012 01:32:43 +0000",
         "Thu, 19 Jul 2012 01:32:43 +0000",
         "Thu, 19 Jul 2012 01:32:40 +0000",
         "Thu, 19 Jul 2012 01:32:39 +0000")

as.POSIXct(dat, format="%a, %d %b %Y %H:%M:%S %z")
#[1] "2012-07-18 20:32:43 CDT" "2012-07-18 20:32:43 CDT" "2012-07-18 20:32:40 CDT" "2012-07-18 20:32:39 CDT"

See ?strptime

Or, if you want numeric

as.numeric(as.POSIXct(dat, format="%a, %d %b %Y %H:%M:%S %z"))
[1] 1342661563 1342661563 1342661560 1342661559
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top