将日期和时间转换为完整日历中的另一种格式

conversion of date and time into another format in full calendar

我在 c# MVC 中使用完整日历。需要从数据库中读取日期。但是我无法使用 JSON 以正确的模式读取它们,因此我需要将日期转换为以下格式。 ..

当前输出Format:2014-06-0116:00

[{"id":"d719381c-b3e4-e311-afa9-eca86bf6cf86","title":"Annual Function","start":"2014-06-01 16:00","end":"2014-06-01 19:00"},{"id":"d719381c-b3e4-e311-afa9-eca86bf6cf86","title":"convocation day","start":"2014-06-24 00:49 12:49","end":"2014-06-24 "}]

要求输出格式:"/Date(1423087200000)/"

[{"id":1259,"title":"bvbvcbc","start":"/Date(1423845000000)/","end":"/Date(1423931400000)/","allDay":false,"description":"Notesbvbvcbc"},{"id":1263,"title":"om nmh sivaay ","start":"/Date(1423087200000)/","end":"/Date(1423432800000)/","allDay":false,"description":"Notesom nmh sivaay "},{"id":1265,"title":"vimal raturi","start":"/Date(1423546200000)/","end":"/Date(1423632600000)/","allDay":false,"description":"Notesvimal raturi"}

您必须使用 Date() 方法来获取 unix 时间戳。

var ob = [
    {"id":"d719381c-b3e4-e311-afa9-eca86bf6cf86","title":"Annual Function","start":"2014-06-01 16:00","end":"2014-06-01 19:00"},
    {"id":"d719381c-b3e4-e311-afa9-eca86bf6cf86","title":"convocation day","start":"2014-06-24 00:49","end":"2014-06-24 12:49"}
];

for (var i = 0; i < ob.length; i++ ){
    var unix_start = new Date(ob[i].start);
    var unix_end = new Date(ob[i].end);
    ob[i].start = '/Date(' + unix_start.getTime() /1000 + ')/';
    ob[i].end = '/Date(' + unix_end.getTime() /1000 + ')/';
}

感谢您的回答,

我在 ajax 成功 属性,

的视图中通过简单地编写以下代码找到了答案
  $.each(data, function (i, item)
                        {
                            item.start = new Date(item.start);
                            item.end = new Date(item.end);
                      });