How to change Sys.time () timezone

I am in PDT timezone and I want to change the "s" variable to 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??

      

+3


source to share


2 answers


Depending on what you want to do exactly, there are several options:

s <- Sys.time()
s
#[1] "2015-06-18 11:21:22 EST"

      

Switching from local time to GMT, without application:

as.POSIXct(format(s),tz="GMT")
#[1] "2015-06-18 11:21:22 GMT"

      



Go to GMT, adjust the time difference between local time and GMT.

`attr<-`(s,"tzone","GMT")
#[1] "2015-06-18 01:21:22 GMT"

      

which is equivalent to an assignment operation:

attr(s,"tzone") <- "GMT"

      

+3


source


You can also use .POSIXct

:



s <- .POSIXct(s, "GMT")

      

+3


source







All Articles