Changing time and dateformat to show correct format on shiny dashboard

女生的网名这么多〃 提交于 2019-12-11 08:11:11

问题


I've build this dashboard with multiple date and time columns however in the dashboard the "T" and "Z" popup in the display Any ideas on how to remove this? I tried as.character, as.factor, anytime but I'm not able to make it happen.

Any other ideas are appreciated!


回答1:


You can parse it in base R or with lubridate :

tz <- Sys.timezone()

date1 <- "2015-03-23T13:23:20Z"

# With {base}
strptime(date1, tz = tz, format = "%Y-%m-%dT%H:%M:%OSZ")
[1] "2015-03-23 13:23:20 CET"


#With lubridate
lubridate::ymd_hms(date1, tz = tz)
[1] "2015-03-23 14:23:20 CET"

You can of course specify a different timezone for tz.

Best,

Colin




回答2:


This happens when you go from R to Javascript. You need to add:

 output$yourDT <- DT::renderDataTable({
     DT::datatable(df) %>% formatDate(3, "toLocaleString")
 })

Where the 3 represents the position of the date (as.POSIXct(), not factor, for example) column (e.g., third column) you are formatting.



来源:https://stackoverflow.com/questions/45651789/changing-time-and-dateformat-to-show-correct-format-on-shiny-dashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!