I'm working on a web app which uses a calendar. When I create a calendar event and select a start time of 10:00am, the event is saved as 09:00am (I'm based in UK and we are UTC+1 currently which I think accounts for the difference.
I'd like to know the best way to handle this, and make sure if a user from any time zone chooses 10:00am on the calendar, that 10:00am is written to the database.
Here are the relevant bits of code. I'm specifically interested in the Start
and Finish
variables which are both Datetime datatypes throughout:
This is the Javascript to catch the event creation:
eventDrop: function (calEvent, dayDelta, minuteDelta, allDay, revertFunc) {
var event = {};
event.EventID = calEvent.eventid;
event.StatusString = "Update";
event.CustomerID = calEvent.customerid;
event.ProductID = calEvent.productid;
event.Title = calEvent.title;
event.Start = new Date(calEvent.start.format());
event.Finish = new Date(calEvent.end.format());
event.EventNote = calEvent.eventNote;
event.ProductValue = calEvent.ProductValue;
That's passed to an SQL handler
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = m_Connection;
cmd.CommandText = "usp_ATP_Calendar_InsertUpdateEvent";
[...other params...]
cmd.Parameters.AddWithValue("@Start", eve.Start);
cmd.Parameters.AddWithValue("@Finish", eve.Finish);
cmd.Parameters.AddWithValue("@EventNote", eve.EventNote);
cmd.ExecuteNonQuery();
I've added an alert to the web page which is just event.Start.toString()
whihc is triggered when an event is saved. It shows this for this example:
So I assume that 10:00+0100 equates to 9:00am which is why my event is getting written away with a 'different' time. Can anyone advise the best way to deal with this, and perhaps provide some example code so that if a user drops an event on 10:00am that is the time that is stored?