I have the dataframe below and I want to display it as DT::datatable()
library(DT)
library(lubridate)
eventex<-structure(list(registration_type = c("Start", "Stopp"), timestamp = c("25.11.2022 13:19:42",
"31.10.2022 14:19:13")), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"))
eventex$timestamp<-as.POSIXct(paste0(eventex$timestamp), format="%d.%m.%Y %H:%M:%S")
datatable(eventex)
why is it displayed like this?
CodePudding user response:
People's definition of "normal" may vary, especially when ambiguous (and irrational) conventions such as commonly used in the US are assumed. There is a formatDate function that can be applied to your datetime column. (The options are not well documented in the R package):
DT:::DateMethods
[1] "toDateString" "toISOString" "toLocaleDateString" "toLocaleString" "toLocaleTimeString"
[6] "toString" "toTimeString" "toUTCString"
datatable(eventex) %>% formatDate(~timestamp, "toLocaleString" )
Further information and worked examples can be found here: https://rstudio.github.io/DT/functions.html