Reputation: 740
I am using the FullCalendar script and am having trouble formatting the date/time of EVENTS on the calendar.
I need all the events date/time data to look like:
2011-09-28 08:15:00
All the dates are like this in my JSON source, which display on the calendar correctly. However, if the event is moved or a new event is added (dropped by eternal dragging), the time format looks like:
Fri Sep 30 2011 14:30:00 GMT-0400 (EDT)
It doesn't DISPLAY in that format, but it appears this way when I try to insert the event.start or event.end into my database, or when I do this:
eventClick: function(event) {
alert("Event ID: " + event.id + " Start Date: " + event.start + " End Date: " + event.end);
}
I am using this only to see how the date & time are saved within the calendar. I need to update my database with new events, but in the format first shown above, but I am having trouble doing this.
How do I use the formatDate
function? I see it listed, and the reason I'm asking is because I don't know what to do with it.
I did:
$.fullCalendar.formatDate(event.start, 'MM-dd-yyyy');
but that doesn't do anything...
Upvotes: 9
Views: 56198
Reputation: 2417
If you are trying to pass date object from java to full calendar and using Java 7 or lesser, below function will work for you.
Date date= new Date("passyourdatestring");
date.toLocaleString();
And following will be the event object.
{
id: '_jobName' ,
url: 'url ',
title: 'title',
allDay: 'false',
description: 'displayname',
start': 'schedDateTime',
end: date.toLocaleString()
}
Upvotes: 0
Reputation: 51
what I did, is, first put it in a var, but only seemed to work in IE - FF still produced the IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST"):
var formDate = $.fullCalendar.formatDate(event.start, 'MM-dd-yyyy');
alert(" Start Date: " + formDate);
Upvotes: 2
Reputation: 13
I have used below code while rendering the event on calendar.
Hope this code help you.
eventRender: function(event, element) {
eventsdate = moment(event.start).format('hh:mm a');
eventedate = moment(event.end).format('hh:mm a');
element.find('.fc-time').html(eventsdate + " - " + eventedate + "<br>");
}
Make sure you are using moment.js
Upvotes: 1
Reputation: 875
Just use the following code before you render your events:
start=moment(start).format('YYYY/MM/DD hh:mm');
end=moment(end).format('YYYY/MM/DD hh:mm');
Make sure you are using moment.js.
Upvotes: 14
Reputation: 2141
I have found your answer in a similar question, in here
Answered by H.D:
dateStr = "Tue Aug 13 2013 18:00:00 GMT-0400 (EDT)"
(new Date(dateStr)).toISOString().slice(0, 10)
It will display: '2013-08-13'
(new Date(dateStr)).toISOString()
It will display: '2013-08-13T18:00:00.000Z'
Upvotes: 1
Reputation: 8220
Q : How do I use the formatDate function? I see it listed, the reason I'm asking is because I don't know what to do with it. I did: $.fullCalendar.formatDate(event.start, 'MM-dd-yyyy'); That doesn't do anything...
Answer :
You can use look likes :
eventClick: function(event) {
alert("Event ID: " + event.id + " Start Date: " + $.fullCalendar.formatDate(event.start, 'MM-dd-yyyy') + " End Date: " + event.end);
}
Upvotes: 0
Reputation: 931
Check out formatDate and parseDate and it'll probably solve your problems.
Upvotes: 0