0

I did this to make some operations with the seconds:

x <- as.numeric(unclass(ISOdatetime(year=2017,
                                month=2,
                                day=9,
                                hour=8,
                                min=38,
                                sec=39,
                                tz="Greenwich")))

x
[1] 1486629519

Now, I want to reverse it. That is, obtain from the 1486629519 the year, month, day, hour, minutes, and seconds as separate objects.

Of course I'm not dealing with just one quantity but with a large vector of seconds.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Mario
  • 1
  • 1

1 Answers1

3

You can use .POSIXct:

R> .POSIXct(1486629519, tz="GMT")
[1] "2017-02-09 08:38:39 GMT"

If you want to easily be able to extract the components, you can convert to POSIXlt:

R> p <- as.POSIXlt(.POSIXct(1486629519, tz="GMT"))
R> p$year + 1900  # years since 1900
[1] 2017
R> p$mon + 1      # months are zero-based
[1] 2
R> p$mday         # mday is day of month; day of year is also available
[1] 9
R> p$hour
[1] 8
R> p$min
[1] 38
R> p$sec
[1] 39
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418