开发者

How to change date format available for use with FullCalendar jQuery plugin

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开发者_如何学C 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜