I am in the PDT timezone and I want to change the variable "s" to the GMT timezone. Any idea how?
s<-Sys.time()
s
as.POSIXct(s,"GMT")
OUTPUT
> s<-Sys.time()
> s
[1] "2015-06-17 17:56:17 PDT"
> as.POSIXct(s,"GMT")
[1] "2015-06-17 17:56:17 PDT" # <-- how do I get this in GMT??
Depending on what you want to do exactly, there are a couple of options:
s <- Sys.time()
s
#[1] "2015-06-18 11:21:22 EST"
Transfer from local time to GMT, without adustment:
as.POSIXct(format(s),tz="GMT")
#[1] "2015-06-18 11:21:22 GMT"
Transfer to GMT, adjusting for the time difference between local time and GMT.
`attr<-`(s,"tzone","GMT")
#[1] "2015-06-18 01:21:22 GMT"
, which is equivalent to the assignment operation:
attr(s,"tzone") <- "GMT"
You can also use .POSIXct
:
s <- .POSIXct(s, "GMT")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With