title: Use JSON.NET to parse json date of format Date(epochTime-offset)
body: <p>I am using Json.net 7.0.1 in C# to consume a rest API. The trouble is with the date format the API uses in its JSON response. It looks like this:</p>
  
  <pre><code>/Date(1445301615000-0700)/
  </code></pre>
  
  <p>That is meant to represent a UTC time of 2015-10-19 17:40:15</p>
  
  <p>If you plug 1445301615000 into an <a href="http://www.epochconverter.com/" rel="noreferrer">epoch time converter</a>, you see that it is 2015-10-<strong>20</strong> <strong>00</strong>:40:15 . So it is 7 hours ahead of UTC. Then they include the -0700 presumably to offset that back to UTC. So, in an effort to give me a UTC time, they are sending me UTC+7-0700. Why they do it this way I have no idea, but I can't change that.</p>
  
  <p>My question is, how best to make Json.NET parse that date string and come up with a DateTime of <code>2015-10-19 17:40:15</code> UTC. I can write a custom JsonConverter to hijack the value and manipulate it manually, but I was wondering if there is a more native method.</p>
  
  <p>I have tried changing the <code>JsonSerializerSettings DateTimeZoneHandling</code> property to all its different values. Setting it to Utc just ignores the time zone offset, yielding <code>2015-10-20 00:40:15</code>. Setting it to Local, Unspecified, or RoundtripKind all yield <code>2015-10-19 20:40:15</code>, which I believe is because my local timezone is UTC-4, so it is trying to apply that adjustment to the main date value of 2015-10-20 00:40.</p>
  
  <p>I also considered using the <code>DateFormatString</code> property to represent the expected date string format. But I could not find the right <a href="https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx" rel="noreferrer">format string characters</a> to represent this epochtime-offset format.</p>
  
  <p>Here's a simplified example:</p>
  
  <pre><code>Person person;
  string json = @"{ 'Name': 'John', 
                    'LastSeen':'/Date(1445301615000-0700)/' }";   // 1445301615000 = 2015-10-20 00:40:15
  
  person = JsonConvert.DeserializeObject&lt;Person&gt;(json);
  Console.WriteLine(person.LastSeen);     // 10/19/2015 8:40:15 PM    Kind = Local
  
  person = JsonConvert.DeserializeObject&lt;Person&gt;(json, new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat });
  Console.WriteLine(person.LastSeen);     // 10/19/2015 8:40:15 PM    Kind = Local
  
  person = JsonConvert.DeserializeObject&lt;Person&gt;(json, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc });
  Console.WriteLine(person.LastSeen);     // 10/20/2015 00:40:15 PM    Kind = Utc
  
  // In all three, the -0700 portion is being ignored. I'd like person.LastSeen to be 10/19/2015 17:40:15.
  </code></pre>
  
  <p>Again, I could just know that the API is going to give me UTC+7 and do the adjustment myself to get real UTC. But I wondered if Json.NET has a native way to handle this type of date string.</p>