title: How to get equivalent time in another timezone
body: <p>I'm trying to compare two times from different timezones, and see whether one is before the other. How would I do this in Go?</p>
  <p><strong>Note</strong>: Basically I would like <code>sfTime.Before(nyTime) == true</code>, but my example below would have <code>sfTime.Before(nyTime) == false</code>. Suggestions on how to make this happen would be great.</p>
  <hr />
  <p>For example, in this code...</p>
  <pre><code>layout := &quot;2006-01-02 15:04 MST&quot;
  sfTime, _ := time.Parse(layout, &quot;2017-03-01 12:00 PDT&quot;)
  nyTime, _ := time.Parse(layout, &quot;2017-03-01 12:00 EDT&quot;)
  
  fmt.Printf(&quot;Are these times equal? %v\n&quot;, sfTime.Equal(nyTime))
  </code></pre>
  <p>This prints:</p>
  <blockquote>
  <p>Are these times equal? true</p>
  </blockquote>
  <p><a href="https://play.golang.org/p/uXkNV4vm7z" rel="nofollow noreferrer">Playground link here</a>.</p>
  <p>Unintuitively, even if you set them to be the same timezone, this only changes the timezone, but not the <code>HH:mm</code> value.</p>
  <pre><code>layout := &quot;2006-01-02 15:04 MST&quot;
  sfTime, _ := time.Parse(layout, &quot;2017-03-01 12:00 PDT&quot;)
  nyTime, _ := time.Parse(layout, &quot;2017-03-01 12:00 EDT&quot;)
  
  // Set timezone to UTC
  utcLocation, _ := time.LoadLocation(&quot;UTC&quot;)
  sfTime = sfTime.In(utcLocation)
  nyTime = nyTime.In(utcLocation)
  
  // Timezones should not be equal, but they are
  fmt.Printf(&quot;Are these times still equal? %v\n&quot;, sfTime.Equal(nyTime))
  fmt.Printf(&quot;The New York Time: %v\n&quot;, nyTime)
  </code></pre>
  <p>Prints</p>
  <blockquote>
  <p>Are these times still equal? true</p>
  <p>The New York Time: 2017-03-01 12:00:00 +0000 UTC</p>
  </blockquote>
  <p><a href="https://play.golang.org/p/JMieai_02t" rel="nofollow noreferrer">Playground link</a>.</p>