changing origin for anytime() R

Viewed 88

I am using the anytime() function and would like to change the starting point of it so that the remainder of my data follows from that origin.

My starting value that I have is 1609459200 where anytime(1609459200) returns "2020-12-31 19:00:00 EST" , but instead I would like anytime(1609459200) = "2021-01-01 00:00:00" so that the rest of my values follow after this. For example anytime(1609459201) = "2021-01-01 00:00:01" and so on within my column of values. Is there a way I can change this? Thanks

1 Answers

1) Use UTC time zone:

anytime(1609459201, tz = "UTC")
## [1] "2021-01-01 00:00:01 UTC"

or use utctime from the anytime package:

utctime(1609459201)
## [1] "2021-01-01 00:00:01 UTC"

or set anytime's time zone to UTC. (Use anytime:::setTZ("") if you want to set it back.)

anytime:::setTZ("UTC")
anytime(1609459201)
## [1] "2021-01-01 00:00:01 UTC"

or with base R:

as.POSIXct(1609459201, origin = "1970-01-01", tz = "UTC")
## [1] "2021-01-01 00:00:01 UTC"

2) Another possibility is to use any of these which were done in the EST time zone.

anytime(1609459201) - anytime(1609459200) + anytime("2021-01-01 00:00:00")
## [1] "2021-01-01 00:00:01 EST"

anytime(1609459201 + 18000)  # 18000 = 5 hours in seconds
## [1] "2021-01-01 00:00:01 EST"

anytime(1609459201) + 18000
## [1] "2021-01-01 00:00:01 EST"
Related