日期格式随DT和闪亮而变化

s.b*_*nel 3 r shiny dt

我的问题是当我在我的计算机上使用数据表而在服务器上formatDate正在改变时我知道我正在使用 method = 'toLocaleDateString'它可能不是很好的方法

在我的电脑上它给我我想要的格式:

1 février 2000 

21 mars 2000
Run Code Online (Sandbox Code Playgroud)

闪亮它给我:

01/02/2000

21/03/2000
Run Code Online (Sandbox Code Playgroud)

本地计算机和服务器都有 Sys.timezone()

[1] "Europe/Paris"
Run Code Online (Sandbox Code Playgroud)

我想这样做

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
Run Code Online (Sandbox Code Playgroud)

谢谢

Yih*_*Xie 5

使用Github上的DT(> = 0.2.2)的开发版本,您可以将其他参数传递给日期转换方法,例如

datatable(a) %>%
  formatDate(1, method = 'toLocaleDateString', params = list('fr-FR'))
Run Code Online (Sandbox Code Playgroud)

或更多参数:

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

  • 嗨@Yihui,谢谢你的回答.更进一步,有没有办法使用这种方法有一个mm-YYYY日期?(我已经尝试在上面的答案中设置day = NULL,但这似乎不起作用.)再次感谢. (4认同)