title: How to format timestamp in outgoing JSON
body: <p>I've been playing with Go recently and it's awesome. The thing I can't seem to figure out (after looking through documentation and blog posts) is how to get the <code>time.Time</code> type to format into whatever format I'd like when it's encoded by <code>json.NewEncoder.Encode</code></p>
  
  <p>Here's a minimal Code example: </p>
  
  <pre><code>package main
  
  type Document struct {
      Name        string
      Content     string
      Stamp       time.Time
      Author      string
  }
  
  func sendResponse(data interface{}, w http.ResponseWriter, r * http.Request){
       _, err := json.Marshal(data)
      j := json.NewEncoder(w)
      if err == nil {
          encodedErr := j.Encode(data)
          if encodedErr != nil{
              //code snipped
          }
      }else{
         //code snipped
      }
  }
  
  func main() {
      http.HandleFunc("/document", control.HandleDocuments)
      http.ListenAndServe("localhost:4000", nil)
  }
  
  func HandleDocuments(w http.ResponseWriter,r *http.Request) {
      w.Header().Set("Content-Type", "application/json")
      w.Header().Set("Access-Control-Allow-Origin", "*")
  
      switch r.Method {
          case "GET": 
              //logic snipped
              testDoc := model.Document{"Meeting Notes", "These are some notes", time.Now(), "Bacon"}    
              sendResponse(testDoc, w,r)
              }
          case "POST":
          case "PUT":
          case "DELETE":
          default:
              //snipped
      }
  }
  </code></pre>
  
  <p>Ideally, I'd like to send a request and get the Stamp field back as something like <code>May 15, 2014</code> and not <code>2014-05-16T08:28:06.801064-04:00</code></p>
  
  <p>But I'm not really sure how, I know I can add <code>json:stamp</code> to the Document type declaration  to get the field to be encoded with the name stamp instead of Stamp, but I don't know what those types of things are called, so I'm not even sure what to google for to find out if there is some type of formatting option in that as well. </p>
  
  <p>Does anyone have a link to the an example or good documentation page on the subject of those type mark ups (or whatever they're called) or on how I can tell the JSON encoder to handle <code>time.Time</code> fields? </p>
  
  <p>Just for reference, I have looked at these pages: <a href="http://pauladamsmith.com/blog/2011/05/go_time.html" rel="noreferrer">here</a> and <a href="https://gobyexample.com/json" rel="noreferrer">here</a> and of course, <a href="http://golang.org/pkg/json/" rel="noreferrer">at the official docs</a></p>