title: JSON omitempty With time.Time Field
body: <p>Trying to json Marshal a struct that contains 2 time fields. But I only want the field to come through if it has a time value. So I'm using <code>json:",omitempty"</code> but it's not working.</p>
  
  <p>What can I set the Date value to so json.Marshal will treat it like an empty (zero) value and not include it in the json string?</p>
  
  <p>Playground: <a href="http://play.golang.org/p/QJwh7yBJlo" rel="noreferrer">http://play.golang.org/p/QJwh7yBJlo</a></p>
  
  <p><strong>Actual Outcome:</strong> </p>
  
  <blockquote>
    <p>{"Timestamp":"2015-09-18T00:00:00Z","Date":"0001-01-01T00:00:00Z"}</p>
  </blockquote>
  
  <p><strong><em>Desired Outcome:</em></strong> </p>
  
  <blockquote>
    <p>{"Timestamp":"2015-09-18T00:00:00Z"}</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
      "time"
  )
  
  type MyStruct struct {
      Timestamp time.Time `json:",omitempty"`
      Date      time.Time `json:",omitempty"`
      Field     string    `json:",omitempty"`
  }
  
  func main() {
      ms := MyStruct{
          Timestamp: time.Date(2015, 9, 18, 0, 0, 0, 0, time.UTC),
          Field:     "",
      }
  
      bb, err := json.Marshal(ms)
      if err != nil {
          panic(err)
      }
      fmt.Println(string(bb))
  }
  </code></pre>