我正在使用 FullCalendar 并且我的事件对象的开始日期存储到数据库中
copiedEventObject.start = date;
我后来检索它并使用以下方法初始化我的日历:
$.ajax({
type: "POST",
url: "Default.aspx/getCalendarEventsData",
data: {},
contentType: "application/json",
dataType: "json",
success: function (msg) {
// Replace the div's content with the page method's return.
calendarStoredEvents = $.map(msg.d, function (item) {
return {
title: item.EventTitle,
start: item.start,
id: item.EventID,
staffID: item.staffID
};
});
initializeCalendar(calendarStoredEvents);
}
});
item.start 是:
2013-06-30T16:00:00.000Z
现在的问题是。如果我在某个星期三存储了我的事件对象,它会检索并显示在星期二。我读了一点,它与时区有关。我试过添加:
ignoretimezone = false (失败,然后尝试将其切换为 true)
ignoretimezone = true (也失败了,然后尝试添加时区)
currentTimezone: 'Asia/Singapore' (效果不佳)
这是存储在数据库中的值:
drop: function (date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = $(this).data('eventObject');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
// render the event on the calendar
// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
// write to database
var eventID = copiedEventObject.id;
var staffID = copiedEventObject.staffID;
var start = copiedEventObject.start;
var end = copiedEventObject.end;
var allDay = copiedEventObject.allDay;
编辑
我的网站托管在 Azure 中,所以我猜时间来自服务器:
当我删除一个事件时
( drop: 函数 (date, allDay))
我使用警报(开始)并显示(我的客户时间)
2013 年 7 月 17 日星期三 00:00:00 GMT+0800(马来半岛标准时间)
我在后面的 C# 代码中写入数据库:
string strConnectionString = ConfigurationManager.ConnectionStrings["PCSDB"].ConnectionString;
SqlConnection conn = new SqlConnection(strConnectionString);
conn.Open();
using (SqlCommand sqlCommand = new SqlCommand("INSERT INTO CalendarData (EventID, staffID, start) VALUES (@EventID, @staffID, @start)", conn))
{
sqlCommand.Parameters.AddWithValue("@EventID", eventID);
sqlCommand.Parameters.AddWithValue("@staffID", staffID);
sqlCommand.Parameters.AddWithValue("@start", start);
int queryResult = sqlCommand.ExecuteNonQuery();
}
conn.Close();
当我检查数据库时,起始值变为
2013-07-16T16:00:00.000Z
编辑 更改为日期时间后,我在数据库中保存了正确的日期。
现在我在为对象转换它时遇到问题。我用了:
var parsedDate = $.fullCalendar.parseDate(item.start);
var formatedDate = $.fullCalendar.formatDate(parsedDate, "dd-MM-yyyy");
通过了
17/7/2013 12:00:00 AM 变为 07-05-2014