[R] Force conversion of (POSIXct) time zone with base R

Eric Berger er|cjberger @end|ng |rom gm@||@com
Thu Aug 22 11:26:59 CEST 2024


as.POSIXct(as.character(now),tz="UTC")

or

as.POSIXct(as.character(Sys.time()),tz="UTC")


On Thu, Aug 22, 2024 at 12:00 PM Iago Giné Vázquez <iago.gine using sjd.es> wrote:

> Hi,
>
> How should POSIXct time zone be changed without modifying the specified
> time (so fix the time zone). I tried
>
> > now <- Sys.time()
> > now
> [1] "2024-08-22 10:56:24 CEST"
> > as.POSIXct(now, tz = "UTC")
> [1] "2024-08-22 08:56:24 UTC"
> > as.POSIXct(now, origin = as.POSIXct("1970-01-01", tz = "UTC"), tz =
> "UTC")
> [1] "2024-08-22 08:56:24 UTC"
> > format(now, tz = "UTC")
> [1] "2024-08-22 08:56:24"
>
> But I want
> "2024-08-22 10:56:24 UTC"
>
> Thanks!
>
> Best regards,
> Iago
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list