Created
July 6, 2019 22:47
-
-
Save JenniferMack/e251c963c23ee88d621e1a37ce60e6ba to your computer and use it in GitHub Desktop.
An easy way to print out two timezones side by side.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"flag" | |
"fmt" | |
"text/tabwriter" | |
"time" | |
) | |
var flagZone = flag.String("z", "UTC", "remote time zone") | |
func init() { | |
flag.Parse() | |
} | |
func main() { | |
tz, e := time.LoadLocation(*flagZone) | |
if e != nil { | |
fmt.Println(e) | |
return | |
} | |
now := time.Now() | |
tt := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) | |
buf := bytes.Buffer{} | |
w := new(tabwriter.Writer) | |
w.Init(&buf, 10, 0, 1, ' ', 0) | |
fmt.Fprintf(w, "%s\t%s\n", tt.Location(), tz) | |
fmt.Fprintln(w, "-------\t-------") | |
for i := 0; i < 24; i++ { | |
l := tt.Add(time.Duration(i) * time.Hour).Format("3:04pm") | |
r := tt.In(tz).Add(time.Duration(i) * time.Hour).Format("3:04pm") | |
fmt.Fprintf(w, "% 7s\t% 7s\n", l, r) | |
} | |
w.Flush() | |
fmt.Println(buf.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: