I have this method in the C# (server) side:
protected double GetAccountTime()
{
return ((DateTime)unit.SomeMethod(DateTime.UtcNow))
.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
.TotalMilliseconds;
}
My local machine time is Eastern, but my application's account time is Mountain. So I want to change it to Eastern to Mountain time. unit.SomeMethod(...)
just takes the current local time (Eastern) and converts it to account time (Mountain).
In the Javascript side:
var now = new Date(<%=GetAccountTime()%>);
alert(now);//doesn't consider the time to be UTC, need to convert
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
alert("UTC: " + now_utc);
The first alert statement gives me Thu Jun 12 2014 09:30:42 GMT-0400 (Eastern Standard Time)
which is incorrect. I convert the time to UTC, so second alert statement gives me UTC: Thu Jun 12 2014 13:30:42 GMT-0400 (Eastern Standard Time)
. This is correct as far as time goes, but the time zone is still Eastern. Does anyone why and how can I fix this?
What my application does (at request of @JonSkeet):
- It will get the time of the account time for different recorded footage (possibly in different locations).
- There will be a timeline-like cursor which needs account time (not local time).
- There will be options which will send the time back to the server side, so knowing the correct offset will make this easier.