FullCalendar displayed at wrong time

3

I'm implementing FullCalendar in a project, I've inserted some Events in the database, and I return them via Json . But by displaying them on the screen, they come with the correct date time, but the display does not show in the correct place.

Example, the data comes with the bank start date of the event at 06:00, but is displayed at 10:00 am.

In the image below, the event has start times at 06:30, and ends at 07:00.

Butitshowsonthescreenthatthetimeis10:30am

MymodelEventos:

publicclassEventos{[Key]publicintID{get;set;}publicstringtitle{get;set;}publicDateTimestart{get;set;}publicDateTime?end{get;set;}publicintStatusEnum{get;set;}}

Mymethodthatlooksforthedatalookslikethis:

publicJsonResultObterEventos(stringstart,stringend){vardb=newAgendaOnlineFc();vardtInicial=Convert.ToDateTime(start).Date;vardtfinal=Convert.ToDateTime(end).Date;varlista=db.Eventos.Where(d=>d.end<dtfinal&&d.start>dtInicial).ToList();returnJson(lista,JsonRequestBehavior.AllowGet);}

ThereturnofmyJsonlookslikethis:

{ID:10,title:"teste", start: "/Date(1495449000000)/", end: "/Date(1495450800000)/", StatusEnum: 0}
ID:10
StatusEnum:0
end:"/Date(1495450800000)/"
start:"/Date(1495449000000)/"
title:"teste"

and my Script ,

$('#calendar').fullCalendar({
    events: '/Home/ObterEventos/'
});

Is there any additional configuration to be made? Or if not where am I going wrong in this implementation?

    
asked by anonymous 22.05.2017 / 15:47

1 answer

4

This is the wrong Timezone problem. I imported the dates here (my time is GMT-5) and I had different values as well.

One package that fixes this is Moment Timezone . I took the following test and printed the dates at the right time (what you registered in the bank):

> moment("/Date(1495449000000)/").tz('America/Sao_Paulo').format("YYYY-MM-DD HH:mm:ss")
< "2017-05-22 06:30:00"

EDIT

You can also set the Controller ancestor (method Initialize ) to the following setting if you want C # to do the conversion for you:

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
    DateFormatHandling = DateFormatHandling.IsoDateFormat,
    DateTimeZoneHandling = DateTimeZoneHandling.Local
};
    
22.05.2017 / 17:04