Dear All,
I would like to learn the proper way to set the default time zone so I get
the correct date for my files. The code below is non-reproducible (sorry)
because it is based on a file on my system, but I hope someone will be able
to help me anyway.
I have a file that was last modified on 4/21/2015:
file.info("E:/snap/q/snap_q_q1_" %+% endPeriod %+% ".txt")$mtime
[1] "2015-04-21 20:26:33 EDT"
When I convert that to a date, I gives me 2015-04-22. I read about
timezones and saw that there are two possible places to set the default
values: One as a system variable and one as an option. To be safe I set
both:
Sys.setenv(TZ='America/New_York')
Sys.getenv("TZ")
options(tz='America/New_York')
getOption("tz")
as.Date(file.info("E:/snap/q/snap_q_q1_" %+% endPeriod %+%
".txt")$mtime)
[1] "2015-04-22"
But as you can see R still gives me the wrong date. I can get the correct
date as follows:
as.Date(file.info("E:/snap/q/snap_q_q1_" %+% endPeriod %+%
".txt")$mtime, tz='America/New_York')
[1] "2015-04-21"
But my question is why is the as.Date function not using the timezone I
have set?
Thank you in advance,
Roger