title: Unmarshal incorrectly formatted datetime
body: <h1>Background</h1>
  <p>I am learning Go and I'm trying to do some JSON unmarshaling of a datetime.</p>
  <p>I have some JSON produced by a program I wrote in C, I am outputting what I thought was a valid <a href="https://www.wikiwand.com/en/ISO_8601" rel="nofollow noreferrer">ISO8601</a> / <a href="https://www.rfc-editor.org/rfc/rfc3339#section-4.2" rel="nofollow noreferrer">RFC3339</a> timezone offset. I'm using <a href="http://man7.org/linux/man-pages/man3/strftime.3.html" rel="nofollow noreferrer"><code>strftime</code></a> with the following format string:</p>
  <pre><code>%Y-%m-%dT%H:%M:%S.%f%z
  </code></pre>
  <p>(Note that <code>%f</code> is not supported by <a href="http://man7.org/linux/man-pages/man3/strftime.3.html" rel="nofollow noreferrer"><code>strftime</code></a> natively, I have a wrapper that replaces it with the nanoseconds).</p>
  <p>This will then produce the following result:</p>
  <pre><code>2016-08-08T21:35:14.052975+0200
  </code></pre>
  <p>Unmarshaling this in Go however will not work:
  <a href="https://play.golang.org/p/vzOXbzAwdW" rel="nofollow noreferrer">https://play.golang.org/p/vzOXbzAwdW</a></p>
  <pre><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;time&quot;
  )
  
  func main() {
      t, err := time.Parse(time.RFC3339Nano, &quot;2016-08-08T21:35:14.052975+0200&quot;)
      if err != nil {
          panic(err)
      }
      fmt.Println(t)
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>panic: parsing time &quot;2016-08-08T21:35:14.052975+0200&quot; as &quot;2006-01-02T15:04:05.999999999Z07:00&quot;: cannot parse &quot;+0200&quot; as &quot;Z07:00&quot;
  </code></pre>
  <p>(Working example: <a href="https://play.golang.org/p/5xcM0aHsSw" rel="nofollow noreferrer">https://play.golang.org/p/5xcM0aHsSw</a>)</p>
  <p>This is because <a href="https://www.rfc-editor.org/rfc/rfc3339#section-4.2" rel="nofollow noreferrer">RFC3339 expects the timezone offset to be in the format <code>02:00</code></a> with a <code>:</code>, but <a href="http://man7.org/linux/man-pages/man3/strftime.3.html" rel="nofollow noreferrer"><code>strftime</code></a> outputs it as <code>0200</code>.</p>
  <p>So I need to fix this in my C program to output the correct format.</p>
  <pre><code> %z     The +hhmm or -hhmm numeric timezone (that is, the hour and
                minute offset from UTC). (SU)
  </code></pre>
  <h1>Question</h1>
  <p>However, now I have a bunch of JSON files with this incorrect format:</p>
  <pre><code>2016-08-08T21:35:14.052975+0200
  </code></pre>
  <p>instead of the correct (with the <code>:</code> in the timezone offset):</p>
  <pre><code>2016-08-08T21:35:14.052975+02:00
  </code></pre>
  <p>but I still want to be able to unmarshal it correctly in my Go program. Preferably two different JSON files with only this difference should parse in the exact same way.</p>
  <p>Regarding marshaling back to JSON, the correct format should be used.</p>
  <p>This is how I have defined it in my <code>struct</code>:</p>
  <pre><code>Time            time.Time `json:&quot;time&quot;`
  </code></pre>
  <p>So the question is, what is the &quot;Go&quot; way of doing this?</p>
  <p>Also in my code example I am using <code>RFC3339Nano</code>. How would I specify that in the metadata for the struct as well? As I have it now with just <code>json:&quot;time&quot;</code> will that ignore the nano seconds?</p>