【问题标题】:How to remove timezone from datatable in Shiny?如何从 Shiny 的数据表中删除时区?
【发布时间】:2017-07-07 01:31:33
【问题描述】:

目前,当我将 PerformanceAnalytics 包中的一些输出包装到 Shiny 的 datatable(DT 包)中时,日期会在浏览器中附加到 T:00:00:00Z

例如,2015-01-31T00:00:00Z 只需要 2015-01-31

如何防止这种情况发生并只显示 yyyy-mm-dd?数据表中是否有我不知道的设置?

测试代码

# sample data from dput 
rets <- structure(c(NA, 0.00262056199999994, 0.000126308999435887, -0.00261834288319462, 
                       0.0367651429321201, -0.00809892429976078, 0.0139021665335084, 
                       -0.0134753927842055, -0.0140747519238918, -0.0163687182009664, 
                       -0.00980900143012819, 0.00832756801047285), 
                  class = c("xts","zoo"),
                  .indexCLASS = c("POSIXct", "POSIXt"), 
                  tclass = c("POSIXct", "POSIXt"),                 
                  .indexTZ = "UTC", tzone = "UTC",
                  index = structure(c(1414800000, 
                                      1417305600, 1419984000, 1422662400, 
                                      1425081600, 1427760000, 1430352000, 
                                      1433030400, 1435622400, 1438300800, 
                                      1440979200, 1443571200), 
                                    tzone = "UTC", 
                                    tclass = c("POSIXct",  "POSIXt")),
                                   .Dim = c(12L, 1L), 
                                   .Dimnames = list(NULL, "nav"))

library(PerformanceAnalytics)
library(DT)
library(xts)

DT::datatable(table.Drawdowns(rets))

什么样的表格

【问题讨论】:

    标签: r date datatable timezone dt


    【解决方案1】:

    可以使用格式化函数,例如:

    DT::datatable(table.Drawdowns(rets)) %>% formatDate(c(1,2,3), method = 'toDateString')
    

    提供:

    【讨论】:

    • 谢谢罗洛。 formatDate baseR 是 tidyverse 的一部分吗?
    • 它是包 DT 的一部分。
    • 也遇到了这个问题,但不允许您获得 "%d-%m-%Y %H:%M:%S" 格式(不是 DT 的辅助函数给出它似乎的格式),只有日期,只有时间,或 T/Z,或“夏令时......”或“GMT”或“UTC”列:stackoverflow.com/questions/56818869/… 并最终使用另一种方法
    猜你喜欢
    • 1970-01-01
    • 2014-12-30
    • 2019-08-09
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2015-08-23
    • 2018-08-18
    相关资源
    最近更新 更多