Running asp.net mvc 2 on win 7 with .net 4.0
I have a controller action method that receives 2 DateTime objects from a form. The UI on the form uses the jQueryUi datepicker (not sure if that maters).
The user who fills out that form will ALWAYS be entering the date/time in Hawaiian time zone.
I want to convert that to UTC time and store it in a database.
When I call TimeZoneInfo.ConverTime(DateTime,TimeZoneInfo,TimeZoneInfo) it returns the exact same datetime as i passed into it without doing any conversion. I checked the debugger and the only thing that changed was it changed the the DateTime.Kind property to DateTimeKind.Utc.
public ActionResult New(ScheduleNew data){
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById( "Hawaiian Standard Time" );
DateTime start = TimeZoneInfo.ConvertTime(data.StartDate, tz, TimeZoneInfo.Utc);
DateTime end = TimeZoneInfo.ConvertTime(data.EndDate, tz, TimeZoneInfo.Utc);
}
I've Tried an alternate version as well with the same results.
public ActionResult New(ScheduleNew data){
DateTime start = new DateTime( data.StartDate.Year, data.StartDate.Month, data.StartDate.Day, data.StartDate.Hour, data.StartDate.Minute, data.StartDate.Second, DateTimeKind.Unspecified );
DateTime end = new DateTime( data.EndDate.Year, data.EndDate.Month, data.EndDate.Day, data.EndDate.Hour, data.EndDate.Minute, data.EndDate.Second, DateTimeKind.Unspecified );
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById( "Hawaiian Standard Time" );
StartDate = TimeZoneInfo.ConvertTime(start, tz, TimeZoneInfo.Utc);
EndDate = TimeZoneInfo.ConvertTime(end, tz, TimeZoneInfo.Utc),
}
ScheduleData is just a simple ViewModel class with two date time Properties called StartDate and EndDate.
I want to emphasize, I don't care where the server is located, I don't care where the user is located. The user will always enter time in the Hawaiian time zone, and the server should always convert that datetime to to UTC.
Basically what I want, is to add 10 hours to the time the user enters (hawaiian to utc) and I could achieve that by just calling .AddHours(10) and it would be just fine. But later on down the road I will need this app to be more flexible.