Running asp.net mvc 2 on win 7 with .net 4.0
I have a controller action method that gets 2 DateTime objects from a form. The user interface in the form uses jQueryUi datepicker (not sure if these matches).
A user who fills out this form will ALWAYS enter a date / time in the Hawaiian time zone.
I want to convert this to UTC and store it in a database.
When I call TimeZoneInfo.ConverTime (DateTime, TimeZoneInfo, TimeZoneInfo), it returns the same time as me, passing it without any conversion. I checked the debugger and the only thing that changed was changing 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 also tried an alternative version 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 - ViewModel , StartDate EndDate.
, , , , . , UTC.
, 10 , ( utc), , .AddHours(10), . , , , .