Change DateTimeOffset.Offset Property?

Viewed 9157

My end goal is to get universal time from client with NO offset - just UTC time. I try to accomplish this like so:

Javascript: (new Date()).toUTCString(), the output of which logs: Thu, 17 Mar 2016 15:13:23 GMT, which is exactly what I need.

Then I take it to server and try to convert it to DateTimeOffset:

string dateTimeOffsetPattern = "ddd, dd MMM yyyy HH:mm:ss 'GMT'"; 

DateTimeOffset clientLoginTime = DateTimeOffset.ParseExact
    (timeStringFromClient, dateTimeOffsetPattern, CultureInfo.InvariantCulture);

Which results in:

3/17/2016 3:13:23 PM -04:00 

Somehow it adjusts the time for my local (Eastern) offset. I do NOT want this to happen, I want it to just return the UTC time, like so:

3/17/2016 3:13:23 PM +00:00

P.S. I did just ask another question about this, and I apologize, since I feel like it should be easy enough, but I don't get it. This should be really simple, but it looks like offset doesn't have a setter (unless I am completely missing some C# basics as usual):

public TimeSpan Offset { get; }
3 Answers
Related