Hello, I have a question regarding the date objects and timezones. 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). But if I use d = as.Date("2024-11-11") or d = as.Date("2024-11-11", tz="America/New_York") the date object is displayed in my RStudio environment as "2024-11-11 UTC". If I try to read the timezone information from the date object in the ways possible for POSIX, I will get NULL as return:
> attr(d, "tzone") NULL Also unclassing the object does not reveal any information about the timezone, unlike for POSIX objects > unclass(d) [1] 20038 In contrast, getting the timezone information with base::format will yield the timezone information > base::format(d, format="%Z") [1] "UTC" As for my current understanding, setting the tz Argument in as.Date will only have an effect if the input is a date-time such as POSIX and else it has no effect and it is not possible to set a timezone for an Date object. But is this the case if there is some timezone information present when using base::format or in the display in the RStudio environment? Is there any way to add timezone information to an Date object (other than UTC) and keeping it a Date object? And if not how is the Date object internally structured, so that it will return "UTC" when using base::format or in the RStudio environment? Is this due to some default behavior of R? Best regards, Luca My Session Info: R version 4.3.2 (2023-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22631) Matrix products: default locale: [1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8 [4] LC_NUMERIC=C LC_TIME=German_Germany.utf8 time zone: Europe/Berlin tzcode source: internal ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.