In the Events web part, the date displayed should reflect the date for the event based on the user’s time zone.
Can this be achieved by client side This is the sample events webpart:
I have till now achieved this: Bind the Events data table to a json object and passing it to client side. Events data table contains date which is fetched from data base,
row["Date"] = Convert.ToDateTime(item["EventDate"].ToString()).ToUniversalTime();
EventsGrid.DataSource = eventsDataTable;
EventsGrid.DataBind();
string jsonServiceData = JsonConvert.SerializeObject(eventsDataTable);
Controls.Add(
new LiteralControl(@"<input type=""hidden"" id=""serviceData"" value='[" + jsonServiceData + "]'/> "));
On client side, ascx page of webpart this is script that calculates offsets and gives the converted date. But somehow the calculations are not giving correct result.
<script type="text/javascript">
$(document).ready(function () {
ModifyDates();
});
function ModifyDates() {debugger;
properties = document.getElementById('serviceData').value;
properties = JSON.parse(properties);
for (var i = 0; i < properties[0].length; i++) {
var date = new Date(properties[0][i].Date);
var offset = new Date().getTimezoneOffset();
var newDate = new Date(date.getTime() + offset * 60 * 1000);
}
}
What still needs to be done:
- how to bind the data back to grid and show it in webpart
- how to get the correct date.