So the root problem was that I didn't read the javascript date output properly. I interpreted this
Thu Dec 17 2015 19:47:38 GMT-0500
as this
(Thu Dec 17 2015 19:47:38 GMT)-0500
when it is actually this
(Thu Dec 17 2015 19:47:38) GMT-0500
The date was coming from the server incorrectly. Matt's intuition is correct is that it's DateTimeKind.Unspecified datetime fields coming from entity framework. Unfortunately, there does not seem to be any good solution to this problem. The linked solution only works for full entities being generated and is no help for projected objects. There does not seem to be an event hook for all materializations.
In my particular case I am creating a model class for a MVC view, so I'm adjusting the setter to look like this:
private DateTime _TimestampUTC;
public DateTime TimestampUTC
{
get { return _TimestampUTC; }
set
{
switch (value.Kind)
{
case DateTimeKind.Unspecified:
_TimestampUTC = DateTime.SpecifyKind(value, DateTimeKind.Utc);
break;
case DateTimeKind.Local:
_TimestampUTC = value.ToUniversalTime();
break;
case DateTimeKind.Utc:
_TimestampUTC = value;
break;
}
}
}
I'm also generating my POCO entities with T4 so I'm doing this with those as well to avoid the reflection overhead given in most other answers you'll see. However the 'best' solution would be some way to specify the DateTimeKind of an entity field and have that carry through any projection made on that field, including anonymous types. But as best as I can tell this is not possible with current versions of EF. As it is, I'll have to remember to do this for each and every UTC DateTime field on all models being pushed to the javascript client.