在FullCalendar中设置列标题日期的格式 [英] Format column header dates in FullCalendar

查看:80
本文介绍了在FullCalendar中设置列标题日期的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to change the format of the dates that appear in the day column headers on the Fullcalendar week/timegrid view:

我正在将V5与moment.js结合使用.

I'm using V5 in conjuction with moment.js.

我在文档中进行了搜索,最终到了这里: https://fullcalendar.io/docs/v5/day-header-render-hooks

Searching through the docs, I ended up here: https://fullcalendar.io/docs/v5/day-header-render-hooks

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

This is the code I've tried when initialising the calendar:

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

这将导致显示每个标头的今天(Thu),而不是正确的日期.

This results in showing today (Thu) for every header, rather than the correct days.

我的下一个问题是我不确定如何相应地格式化其余日期-这以date对象的'weekday'元素为目标,但我不知道如何将整个日期格式化为一个去(如果可能的话).例如,我希望仅显示星期四14".

My next issue is that I'm not sure how to format the rest of the date accordingly - this targets the 'weekday' element of the date object, but I couldn't figure out how to format the whole date in one go (if that's possible). I'm looking to simply display 'Thu 14th', for example.

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

Any help or advice appreciated!

推荐答案

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

新功能提供了 args 而不是 date 对象.因此,您可以使用 args.date 访问它们,然后使用 moment

The new function supplies args instead of date object. So you access them with args.date and then format using moment

这篇关于在FullCalendar中设置列标题日期的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆