0

I'm using the 'FullCalendar' jQuery plugin however the format of my date string data is only in this format dd-MMM-yyyy HH:mm:ss.

How can I parse this into the FullCalendar plugin so it is in one of the appropriate date formats that the plugin accepts?

I assume I need to utilise the formatDate but I don't know how or where to use this.

Christian Payne
  • 7,081
  • 5
  • 38
  • 59
Adam Wilson
  • 81
  • 3
  • 12

2 Answers2

1

You are going to get into a world of pain if you start playing around with date formats like that.

Update

Based on your comments, I would look at reformatting your input date (do this in javascript). This question shows the many ways to do this.

Community
  • 1
  • 1
Christian Payne
  • 7,081
  • 5
  • 38
  • 59
  • Thanks Christian. I am not using any language. The date output I have to work with is from the CMS I'm using and I have no control over it. I need to convert the given date format into one FullCalendar will accept. Is this going to be too difficult do you think? and should I find an alternative? – Adam Wilson Sep 11 '11 at 02:14
1

Even though I guess I could get some downvotes for this answer, here we go :-)

function myParseDate(indate){ //indate in your format eg. '15-September-2011 13:37:00'
    var datearraytmp1 = indate.split('-');
    var datearraytmp2 = datearraytmp1[2].split(' ');
    var datearraytmp3 = datearraytmp2[1].split(':');
        var datearray = [datearraytmp1[0], datearraytmp1[1], datearraytmp2[0], datearraytmp3[0], datearraytmp3[1], datearraytmp3[2]];
    var jsDate = new Date(datearray[2], monthStringToNumber(datearray[1]), datearray[0], datearray[3], datearray[4], datearray[5], 0);
}


var monthNames = {"January":0, "February":1, "March":2, "April":3, "May":4, "June":5, "July":6, "August":7, "September":8, "October":9, "November":10, "December":11};
function monthStringToNumber(monthname) {
    return monthNames[monthname];
} 

This will give you the jsDate as a JavaScript date object which you can use with fullCalendar without too much problem. N.B that monthNames need to be changed into your language.

It's an ugly but working solution.

Edit: A cleaner solution would be to use http://www.datejs.com/ which seems to parse your input just fine :P

Magnus Winter
  • 921
  • 9
  • 20
  • Just to make clear, @Christian Payne's solution is cleaner in most cases, but if you REALLY can't change the input this will at least get you a bit further with your coding :) – Magnus Winter Sep 16 '11 at 14:29