0

私は 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

今の問題はそれです。ある水曜日のときにイベント オブジェクトを保存すると、代わりに火曜日に取得されて表示されます。少し調べてみたところ、TimeZone と関係があります。私は追加しようとしました:

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;

編集

私の Web サイトは Azure でホストされているため、時間はサーバーからのものだと思います。

イベントをドロップしたとき

( ドロップ: 関数 (日付、全日))

私はアラート(開始)を使用し、それが表示されました(私のクライアント時間)

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 になります

4

2 に答える 2

1

データベースに保存する前に、日付をフォーマットformatDateに変換する必要があります。イベントは、dd-MM-yyyy 00:00:00 のような形式のみを受け入れます。

これは select メソッドに含まれているため、イベント オブジェクトを適切にフェッチしていない可能性があります。これは私にとってはうまくいきます。

select: function(start, end, allDay){

      var startdate = $.fullCalendar.formatDate(start, "dd-MM-yyyy");
      var enddate = $.fullCalendar.formatDate(end, "dd-MM-yyyy");     

      alert(startdate);
      alert(enddate);
 }

これにより、15-07-2013 のような日付が表示されます。

于 2013-07-14T20:02:41.887 に答える