私の解決策は、常にクライアントの FullCalendar から UNIX タイムスタンプまたは UTC 日付形式でサーバーからイベントを送信することです。
まず、jquery-json プラグインを使用してクライアントから送信されたイベントは次のようになります。
var event ={"startDate" : startDate, "endDate" : endDate,"allDay" : allDay};
$.ajax({
url : "${feedbackURL}", type: 'POST', contentType: 'application/json;charset=UTF-8'
,dataType: (($.browser.msie) ? "text" : "xml"), data : $.toJSON(event)
});
$.toJSON() でシリアル化されたイベントは、UTC format でフォーマットされます"yyyy-MM-dd'T'HH:mm:ss'Z'"。
次に、gson と jodatime を使用して UTC 形式の日付を解析できます
private static final DateTimeFormatter UTC_FORMAT = DateTimeFormat
.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(DateTimeZone.UTC);
public static final JsonDeserializer<Date> DATE_DESERIALIZER = new JsonDeserializer<Date>() {
/**
* @see org.apache.wicket.datetime.DateConverter#convertToObject(String,
* java.util.Locale)
*/
@Override
public Date deserialize(final JsonElement json, final Type typeOfT,
final JsonDeserializationContext context)
throws JsonParseException {
String value = json.getAsString().replace(".000", "");
try {
MutableDateTime dt = UTC_FORMAT.parseMutableDateTime(value);
return dt.toDate();
} catch (final Exception e) {
LOG.debug("Date parsing error", e);
throw new ConversionException(e);
}
}
};
次に、org.apache.wicket.datetime.markup.html.form.DateTextFieldまたはで日付を表示しますorg.apache.wicket.datetime.markup.html.basic.DateLabel。
クライアントのタイムゾーンの問題に対処するには、これらをApplication
// always set your application's DateTimeZone to UTC
TimeZone.setDefault(TimeZone.getTimeZone("etc/UTC"));
DateTimeZone.setDefault(DateTimeZone.UTC);
// detect client's timezone in the WebClientInfo
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
最後に、サーバーからクエリを実行し、UNIX タイムスタンプを使用してクライアントの FullCalendar にイベントを送信します。
//Java
long toTimestamp(final Date date) {
return date.getTime() / 1000;
}
Date fromTimestamp(final long timestamp) {
return new Date(timestamp * 1000);
}
生成されたjsonはこのようなものです
[{"id":"1","title":"test1","allDay":true,"start":1299805200,"end":1299807000,"editable":false},
{"id":"2","title":"test2","allDay":false,"start":1299805200,"end":1299807000,"editable":true}]