Reputation: 27382
I am working on one project and i am using FullCalendar
and jQuery dialog.
I am using jQuery
dialog because user select any time-slot they will be see one dialog box and inside of that dialog box i will pass start and end time.
But problem is that fullCalendar
pass start
argument as date object
which is Date {Tue Apr 02 2013 00:00:00 GMT+0530 (India Standard Time)}
now problem is that how can just display 02-04-2013 00:00:00
i do not want to use more plugin as its already have too much js included.
What i have?
jQuery Dialog code
$( "#dialog-form" ).dialog({
autoOpen: false,
modal: true,
buttons:
{
"Create an event": function()
{
var bValid = true;
if ( bValid )
{
//adding event to calendar code
$( this ).dialog( "close" );
}
},
Cancel: function()
{
$( this ).dialog( "close" );
}
},
close: function()
{
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
FullCalendar
var calendar = $('#calendar').fullCalendar(
{
header:
{
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay)
{
console.log(start);
$("#dialog-form input#start_time").val(start);
$("#dialog-form input#end_time").val(end);
$( "#dialog-form" ).dialog( "open" );
calendar.fullCalendar('unselect');
},
I pasted only half code here because its too long and its not necessary to add it here.
Thanks
Upvotes: 1
Views: 269
Reputation: 17257
Full calendar has a built in conversion utility
$.fullCalendar.formatDate( date, formatString [, options ] )
start is a date object so you can do something as below
var curDate = start.getDate();
var curMonth = (parseInt(start.getMonth())+1);
var curYear = start.getFullYear();
alert(curDate+'-'+curMonth+'-'+curYear);
here is a Live fiddle example.
Upvotes: 0
Reputation: 27382
Well Thanx guys for looking and commenting on question but i found it out.
var startDate = start.getFullYear() + "-" + getOtherFiled(start.getMonth()) + "-" + getOtherFiled(start.getDate()) + " " + getOtherFiled(start.getHours()) + ":" + getOtherFiled(start.getMinutes()) + ":" + getOtherFiled(start.getSeconds());
function getOtherFiled(obj)
{
if (obj<10)
return "0"+obj;
return obj;
}
above code successfully output '2013-03-03 02:30:00'
and so on.
Upvotes: 1