tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
728 stars 207 forks source link

Time is cut for datetimes with HH:MM:SS = 00:00:00 #1112

Closed adrupp closed 1 year ago

adrupp commented 1 year ago

When I try to convert a datetime character vector or string, where the time is 00:00:00, the time is cut:

lubridate::ymd_hms(c("2023-01-01 00:00:00", "2023-01-01 00:00:00"))
#> [1] "2023-01-01 UTC" "2023-01-01 UTC"

I would expect, that the items in the vector will be formated into POSIXct like this:

#> [1] "2023-01-01 00:00:00 UTC" "2023-01-01 00:00:00 UTC"
vspinu commented 1 year ago

This is how R prints datetimes (aka POSIXct). If you see "UTC" in the printed version then it's a POSIXt, otherwise it's a Date object.

You can format it explicitly as well

format(ymd_hms("2023-01-01 00:00:00"), format = "%Y-%m-%d %H:%M:%S")
[1] "2023-01-01 00:00:00"