问题
I'm trying to convert my datetime from a csv to POSIXct for data analysis. I've tried multiple codes but either get NA or a wrong format.
The code I'm currently using is
GRS$datetimelocal<-
GRS$`datetime` %>%
ymd_hms(tz="UTC") %>% # first convert the `Date and Time (UTC)`
column into a 'POSIX' format
with_tz(tzone="Australia/Brisbane") # convert to local
"Australia/Brisbane" date time (UTC + 10hrs)
My datetime column is in the format dd/mm/yy hh:mm:ss.
datetime
26/03/2013 21:50
26/03/2013 21:56
26/03/2013 21:58
28/03/2013 07:42
However the new column spits out as
datetimelocal
2026-03-20 13:21:50
2026-03-20 13:21:56
2026-03-20 13:21:58
2028-03-20 13:07:42
Any help would be much appreciated
回答1:
Why not use as.POSIXct
directly?
as.POSIXct("26/03/2013 21:50",
format = "%d/%m/%Y %H:%M",
tz = "Australia/Brisbane")
## [1] "2013-03-26 21:50:00 AEST"
来源:https://stackoverflow.com/questions/49919618/lubridate-not-converting-datetime-to-posixct-correctly-in-r-dd-mm-yy-hhmmss