如何以12H而非24H格式以全日历显示事件

时间:2019-02-27 14:36:09

标签: jquery fullcalendar time-format

我有一堆日历都来自网站上的Google日历,除了以24h格式显示的事件外,其他所有功能都很好。

我试图在jQuery代码中进行设置,但是我找不到正确的代码来实现。在Google日历设置中,它们都设置为12H,因此必须在fullCalendar中设置。

这是我进行搜索时可以找到的唯一代码,它似乎没有做任何事情:

$(function() {
  $('#calendar').fullCalendar({
    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay'
    },
    timeFormat: 'h(:mm)t',
    timezone: 'America/Toronto',
    googleCalendarApiKey: 'hidden',
    eventSources: [{
      googleCalendarId: 'hidden',
      className: 'calendar'
    }]
  });
});

timeFormat是控制它的正确行吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

timeFormat选项是正确的设置。

现在,您需要consult the momentJS documentation(与此fullCalendar documentation链接(又与timeFormat documentation链接))知道可以使用哪种格式的字符串来显示时间以您想要的格式。

例如:

timeFormat: "HH:mm"

将为您提供24小时的服务时间,例如21:00等。如果需要显示一些稍有不同的内容,可以自行修改。

演示:http://jsfiddle.net/8bx14goh/