[R] Question about Date Object and time zones
Ivan Krylov
|kry|ov @end|ng |rom d|@root@org
Wed Sep 25 11:40:37 CEST 2024
24 сентября 2024 г. 17:10:13 GMT+03:00, Luca Brinkmann via R-help <r-help using r-project.org> пишет:
> My current
> understanding is, that a Date object does only save the days from the
> origin and no more information about timezones or other information
> (please correct me if I am wrong).
You are correct.
> the date object is displayed in my RStudio environment as "2024-11-11
> UTC".
This looks like a result of as.POSIXlt(<Date object>).
> In contrast, getting the timezone information with base::format will
> yield the timezone information
> > base::format(d, format="%Z")
> [1] "UTC"
That's an implementation detail: the format() method for Date objects conjures a temporary POSIXlt object and formats the result, and POSIXlt objects can contain time zone information.
> Is there any way to add timezone information to an Date
> object (other than UTC) and keeping it a Date object?
Not with a plain 'Date'. What should a date in a timezone mean? Start of day? End of day? The whole 24-hour interval (except when it lasts 23 or 25 hours due to DST)?
Perhaps you could store one (or two for an interval) POSIXt object(s) if you need timezone information for your dates.
--
Best regards,
Ivan
More information about the R-help
mailing list