r - as.POSIXct gives an unexpected timezone -


i'm trying convert yearmon date (from zoo package) posixct in utc timezone. tried do:

> as.posixct(as.yearmon("2010-01-01"), tz="utc") [1] "2010-01-01 01:00:00 cet" 

i same when convert date:

> as.posixct(as.date("2010-01-01"),tz="utc") [1] "2010-01-01 01:00:00 cet" 

the way work pass character argument:

> as.posixct("2010-01-01", tz="utc") [1] "2010-01-01 utc" 

i looked documentation of datetimeclasses, tzset , timezones. /etc/localtime set europe/amsterdam. couldn't find way set tz utc, other setting tz environment variable:

> sys.setenv(tz="utc") > as.posixct(as.date("2010-01-01"),tz="utc") [1] "2010-01-01 utc" 

is possible directly set timezone when creating posixct yearmon or date?

edit:

i checked functions as.posixct.yearmon. 1 passes as.posixct.date.

> zoo:::as.posixct.yearmon function (x, tz = "", ...)  as.posixct(as.date(x), tz = tz, ...) <environment: namespace:zoo> 

so joshua says timezone gets lost in as.posixct.date. i'll use richies suggestion set tzone hand using:

attr(x, "tzone") <- 'utc'

this solves issue of lost tzone, used presentation , not internally grothendieck , dwin suggested.

this because as.posixct.date doesn't pass ... .posixct.

> as.posixct.date function (x, ...)  .posixct(unclass(x) * 86400) <environment: namespace:base> 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -