On 9 January 2015 at 11:50, janus Larsen wrote: | Hi, | How do I set the timezone on an Rcpp::Datetime? | Thanks in advance, | Sunaj | | This returns "1970-01-01 01:00:00 CET" (computer setting), but I want GMT...
R does the formatting in its session based on your locale. That is generally the right thing: | // [[Rcpp::export]] | Rcpp::Datetime test() { | double d=0; | return(d); | } Small corrections to your code to actually export the function (under a safer name): #include <Rcpp.h> // [[Rcpp::export]] Rcpp::Datetime timetest(double d=0) { return(d); } Then: R> sourceCpp("/tmp/timeQ.cpp") R> timetest() # my default is Chicago, or -5 [1] "1969-12-31 18:00:00 CST" R> as.numeric(timetest()) [1] 0 R> Sys.setenv("TZ"="Europe/London") R> timetest() # I can select another one [1] "1970-01-01 01:00:00 BST" R> Sys.setenv("TZ"="UTC") R> timetest() # incl UTC [1] "1970-01-01 UTC" R> R> format(timetest(), tz="America/Chicago") [1] "1969-12-31 18:00:00" R> So you need to change the timezone _at the level of your app_ which can be as simple as writing a new Date formatter in R as per my last line. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel