date format change with DT and shiny

时光毁灭记忆、已成空白 提交于 2019-12-10 18:13:27

问题


my problem is when i use datatable on my computer and on the server formatDate is changing i know i'm using method = 'toLocaleDateString' maybe it's not the good method

on my computer it give me the format i want :

1 février 2000 

21 mars 2000

on shiny it give me :

01/02/2000

21/03/2000

local computer and server have Sys.timezone()

[1] "Europe/Paris"

im trying to do it like this

a <-structure(list(timestamp = structure(c(949363200, 953596800, 
                                         961286400, 962582400,     965347200,     969667200), 
                                       class = c("POSIXct",  "POSIXt"), tzone = "UTC"), 
                 anoms = c(1, 1, 1, 1, 1, 2), syndrome = c("Acrosyndrome", 
                                                       "Acrosyndrome", "Acrosyndrome", "Acrosyndrome", "Acrosyndrome", 
                                                       "Acrosyndrome")), .Names = c("timestamp", "anoms", "syndrome"
                                                       ), row.names = c(NA, 6L), class = "data.frame")

datatable(a) %>% formatDate(  1, method = 'toLocaleDateString')
a

Thank you


回答1:


With the development version of DT (>= 0.2.2) on Github, you can pass additional parameters to the date conversion method, e.g.

datatable(a) %>%
  formatDate(1, method = 'toLocaleDateString', params = list('fr-FR'))

Or more parameters:

datatable(a) %>% formatDate(
  1, method = 'toLocaleDateString',
  params = list('fr-FR',  list(year = 'numeric', month = 'long', day = 'numeric'))
)


来源:https://stackoverflow.com/questions/38875173/date-format-change-with-dt-and-shiny

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