formatTime with “h” instead of “:” as separator

孤人 提交于 2019-12-13 02:27:11

问题


In France, we use the following 24 hour format for time: 18h30.

Therefore, I want to add the "h" char in the timeFormat option of FullCalendar 2. I found an older post here: formatTime with "h" instead of ":" as separator but the solution is apparently not working anymore with FullCalendar v2.

Is there a way I could "escape" the "h" character in the timeFormat option ?


回答1:


Fullcalendar uses Moment.js for date/times.

Escaping Characters:

To escape characters in format strings, you can wrap the characters in square brackets.

moment().format('[today] dddd'); // 'today Sunday'

This works for the formatTime fullcalendar option too:

timeFormat: 'H[h](mm)'

Demo JSFiddle




回答2:


You cannot escape it, however you can use the eventRender method to do the trick for you.

When the event is being rendered parse the DOM and replace the occurrence of : with h.

            timeFormat: "H:mm",
            eventRender: function(event, element) {
                element.find('.fc-time').text(function () {
                    return $(this).text().replace(":", "h"); 
                });
            }


来源:https://stackoverflow.com/questions/28127435/formattime-with-h-instead-of-as-separator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!