【问题标题】:Format column header dates in FullCalendar在 FullCalendar 中格式化列标题日期
【发布时间】:2020-05-14 18:45:00
【问题描述】:

我一直在尝试更改 Fullcalendar 周/时间网格视图中日期列标题中显示的日期格式:

我将 V5 与 moment.js 结合使用。

通过文档搜索,我最终来到了这里:https://fullcalendar.io/docs/v5/day-header-render-hooks

这是我在初始化日历时尝试过的代码:

dayHeaderFormat: function(date){
    return moment(date.weekday).format('ddd');
}

这会导致每个标题都显示今天(星期四),而不是正确的日期。

我的下一个问题是我不确定如何相应地格式化其余日期 - 这针对日期对象的“工作日”元素,但我不知道如何将整个日期格式化为一个去(如果可能的话)。例如,我希望简单地显示“Thu 14th”。

任何帮助或建议表示赞赏!

【问题讨论】:

  • 意在补充,我根据文档首先尝试了“dayHeaderContent”选项,两者似乎给出了相同的结果。

标签: javascript fullcalendar momentjs fullcalendar-5


【解决方案1】:
dayHeaderContent: (args) => {
    return moment(args.date).format('ddd Do')
}

新函数提供args 而不是date 对象。所以你用args.date访问它们,然后用moment格式化

【讨论】:

    【解决方案2】:

    你可以使用

    dayHeaderContent: (args) => {
    return moment(args.date).format('ddd Do')
    }
    

    我在一个月内遇到问题......从一月开始的月份,这是六月

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多