最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - FullCalendar: Changing event start date and time format - Stack Overflow

programmeradmin2浏览0评论

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:

<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>

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:

<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>
Share Improve this question edited Feb 26, 2012 at 22:00 JCM asked Feb 26, 2012 at 20:59 JCMJCM 831 gold badge3 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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

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:

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>
发布评论

评论列表(0)

  1. 暂无评论