JavaScript SP.CamlQuery() return DateTime fields with offset (in my case +11 hours). In standart Display/Edit forms and views display correct DateTime.
How to get correct DateTime via SP.CamlQuery()?
UPD: JS to get list items
var caml = new SP.CamlQuery();
caml.set_viewXml(...);
var bookingsItems = this._bookingsList.getItems(caml);
this._context.load(bookingsItems);
this._context.executeQueryAsync(function (sender, args) {
var enumerator = bookingsItems.getEnumerator();
var items = [];
while (enumerator.moveNext()) {
var listItem = enumerator.get_current();
var bookingStart = listItem.get_item('BookingStart') // DateTime
}
}, this._QuerylogProcess);
For example bookingStart = 2012-8-14 12:00. If open DispForm.aspx for this listItem bookingStart = 2012-8-14 1:00
UPD: Solution with server insert: C# code to calculate web reginal settings offset:
private TimeSpan _GetUtcOffset(SPWeb web)
{
DateTime utcDate = DateTime.UtcNow;
DateTime localDate = web.RegionalSettings.TimeZone.UTCToLocalTime(utcDate);
return localDate - utcDate;
}
JavaScript function to calculate correct dateTime
var dateTimeCalculateConsideringWebRegionalSettings = function(date){
var utcOffsetMinutes = <%= Convert.ToInt32(UtcOffset.TotalMinutes) %> + new Date().getTimezoneOffset();
var newDate = new Date(date.getTime());
newDate.setTime(newDate.getTime() + (utcOffsetMinutes*60*1000));
return newDate;
}
Use js function:
var bookingStart = dateTimeCalculateConsideringWebRegionalSettings(listItem.get_item('BookingStart'));