Hi,
I had a very similar problem to the original poster. I thought I would post how I got around it in case it helps anyone else.
I found that changing the fields in the model to DateTimeOffset didn't work as it was storing the timezone as UTC not mountain time. This is an internal web app so I don't have to worry about globalization.
In my model the field is set up as "DateTime?". (It can be null). I wrote an extension method. It looks like this:
public static class DateTimeExtensions
{
public static DateTime? GetLocalDateTime(this DateTime? dateTimeVal)
{
if (dateTimeVal != null)
{
DateTime dateTime = new DateTime();
dateTime = dateTimeVal.GetValueOrDefault().ToLocalTime();
return dateTime;
} else
{
return null;
}
}
}
In the update method you do something like this:
myUpdObj.DateTimeField = myCRUDModelObj.DateTimeField.GetLocalDateTime();
In my testing it is working as desired. It is saving the datetime to the database correctly and retrieving it as expected.
Chris