javascript FullCalendar:更改事件开始日期和时间格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9457090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 06:43:40  来源:igfitidea点击:

FullCalendar: Changing event start date and time format

javascriptjquery-pluginsfullcalendar

提问by JCM

I am pulling my Google Calendar feed to fullcalendar. When I view the event details, the start time displays like this: Sun Feb 19 2012 15:00:00 GMT-0500 (Eastern Standard Time). I would prefer if it looked a little more 'normal' - maybe like this: Sunday, February 19, 2012 @ 3:00pm (EST). I have read about formatdate, etc., but I still cannot get a grasp for what I actually need to do to change the format of the date and time. I have been reading related topics in this forum, but at this point they are just confusing me more. Thank you very much in advance for any help! My fullcalendar code is below:

我正在将我的 Google 日历提要拉到 fullcalendar。当我查看事件详细信息时,开始时间显示如下:Sun Feb 19 2012 15:00:00 GMT-0500(东部标准时间)。我希望它看起来更“正常”一点 - 可能是这样的:2012 年 2 月 19 日星期日下午 3:00(美国东部标准时间)。我已经阅读了 formatdate 等内容,但我仍然无法理解我实际需要做什么来更改日期和时间的格式。我一直在阅读这个论坛中的相关主题,但在这一点上,它们只是让我更加困惑。非常感谢您的帮助!我的全日历代码如下:

<script type="text/javascript">
        $(document).ready(function() {
            $('#calendar').fullCalendar({
                  eventClick: function(calEvent, jsEvent, view) {
                    $.colorbox({
                        maxWidth:"800px", html:"<h1>"+calEvent.title+"</h1><h2>When</h2><p>"+calEvent.start+"</p><h2>Where</h2><p>"+calEvent.location+"</p><h2>"+calEvent.eventTime+"</h2><p>"+calEvent.description+"</p>"});
                  },
                  events:
                        {
                        url: 'my google calendar feed url'
                        }
            });
        });
</script>

回答by Doug

You want to change the formatDate bit where it says "HH:mm" to the appropriate letters for what you're looking for here.

您想将显示“HH:mm”的 formatDate 位更改为您在此处查找的相应字母。

For what you're after (minus the EST bit which doesn't seem to be in the formatDate function) you're after something like this:

对于您所追求的(减去似乎不在 formatDate 函数中的 EST 位),您所追求的是这样的:

var eventTime = $.fullCalendar.formatDate(calEvent.start, "dddd, MMMM yyyy @ h:sstt")+" to "+
                $.fullCalendar.formatDate(calEvent.end, "dddd, MMMM yyyy @ h:sstt");

Edit: As I understand it...

编辑:据我所知......

<script type="text/javascript">
    $(document).ready(function() {
        $('#calendar').fullCalendar({
              eventClick: function(calEvent, jsEvent, view) {
        var eventTime = $.fullCalendar.formatDate(calEvent.start, "dddd, MMMM yyyy @ h:sstt")+" to "+
                        $.fullCalendar.formatDate(calEvent.end, "dddd, MMMM yyyy @ h:sstt");
        $.colorbox({
          maxWidth:"800px",
          html:"<h1>"+calEvent.title+"</h1>"+
             "<h2>When</h2>"+
             "<p>"+eventTime+"</p>"+
               "<h2>Where</h2>"+
               "<p>"+calEvent.location+"</p>"+
               "<p>"+calEvent.description+"</p>"});
        },
        events:
        {
            url: 'my google calendar feed url'
        }
     });
        });
</script>