Using FullCalendar with MVC 4 and C#, unable to get the start and end param values

柔情痞子 提交于 2020-01-07 04:50:55

问题


When my FullCalendar (v 2.3.1) attempts to get its event data in my Controller code, start and end parameters object looks like this:

start=1425186000
end=1428811200

The documentation states that I should be getting ISO8601 dates as the parameters but obviously I am not.

How do I get the FullCalendar to provide ISO8601 dates? What are the numbers that I am actually getting?


回答1:


That is the UNIX timestamp, and in your case represents March 1, 2015 (start) to April 12, 2015 (end).

A Unix timestamp (or epoch time) is the number of seconds that have elapsed since January 1, 1970 00:00 UTC. src

You can get either convert the unix timestamp (shown below) or the better solution would be to simply feed the ISO date to the calendar. This SO post discusses how to convert a DateTime to ISO.

$('#fullCal').fullCalendar({
  events: [{
    title: 'Random Event',
    start: moment().add(1, 'h'),
    end: moment().add(2, 'h'),
    allDay: false
  }, {
    title: 'Your Event Unix... No work!', //this is probably what your current code is doing
    start: 1425186000,
    end: 1428811200,
    allDay: false
  }, {
    title: 'Your Event Unix... work!', //this will work
    start: moment.unix(1425186000),
    end: moment.unix(1428811200),
    allDay: false
  }],
  header: {
    left: '',
    center: 'prev title next today',
    right: ''
  },
  timezone: 'local'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.js"></script>

<div id="fullCal"></div>


来源:https://stackoverflow.com/questions/28972771/using-fullcalendar-with-mvc-4-and-c-unable-to-get-the-start-and-end-param-valu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!