Question

I have number of seconds elapsed since an epoch and can convert it to localtime in python, like so

time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(1378182603));
## yields '2013-09-03 10:00:03'

How can I achieve the same in R?

Was it helpful?

Solution

 x<-as.POSIXct(1378182603, origin="1970-01-01")
 strftime(x, format= "%Y-%m-%d %H:%M:%S")
#[1] "2013-09-03 05:30:03"

It is processed as though it is recorded in UCT but output as if in the America/New_York timezone.

 x<-as.POSIXct(1378182603, origin="1970-01-01")
 strftime(x, format= "%Y-%m-%d %H:%M:%S", tz="America/Los_Angeles")
#[1] "2013-09-03 02:30:03"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top