I am trying to create date-time using lubridate package, and I've tried the following values:
library(lubridate)
ymd_hms("2017-07-02 23:00:00")
[1] "2017-07-02 23:00:00 UTC"
ymd_hms("2017-07-02 00:00:00")
[1] "2017-07-02 UTC"
It seems that if you type the time at midnight, 00:00:00, the ymd_hms() method ignores the time value, and the result becomes a date. Is there any way to show the 00:00:00 in the result? Thanks a lot!
lubridate: Make Dealing with Dates a Little EasierFunctions to work with date-times and time-spans: fast and user friendly parsing of date-time data, extraction and updating of components of a date-time (years, months, days, hours, minutes, and seconds), algebraic manipulation on date-time and time-span objects.
Lubridate makes it easier to do the things R does with date-times and possible to do the things R does not. If you are new to lubridate, the best place to start is the date and times chapter in R for data science.
lubridate is part of Hadley's tidyverse ecosystem but is not loaded by the tidyverse package, which includes only what he thought were the core components.
So I just got my own answer to this question after google searches and error trying:
mydates <- format(as.POSIXct("2011-01-01 00:00:00", tz = "UTC"), "%m-%d-%Y %H:%M:%S")
mydates
[1] "01-01-2011 00:00:00"
format(as.POSIXct("2011-01-01 00:00:00", tz = "UTC"), "%m-%d-%Y %H:%M:%S")
[1] "01-01-2011 00:00:00"
It seems that using the R Base as.POSIXct with format arguments works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With