1

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

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90

3 Answers3

3
$.fullCalendar.formatDate( start, 'dd-MM-yyyy HH:mm:ss' );
Ketan Modi
  • 1,780
  • 1
  • 16
  • 28
1

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.

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
0

update

Full calendar has a built in conversion utility

$.fullCalendar.formatDate( date, formatString [, options ] )

Old answer

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.

Jay Mayu
  • 17,023
  • 32
  • 114
  • 148
  • getting the time from the date object is just as getting date and year right? `gethours()`, `getMiniutes()`. [Full reference here](http://www.w3schools.com/jsref/jsref_obj_date.asp#gsc.tab=0). btw there is built in utility for full calendar for date conversion. – Jay Mayu Apr 02 '13 at 06:46
  • ahh I see that in your answer :) – Jay Mayu Apr 02 '13 at 06:47