misc-tools/go/convert-epoch/convert-epoch.go
2021-09-15 09:26:15 -04:00

48 lines
1.1 KiB
Go

package main
import (
"flag"
"fmt"
"strconv"
"time"
)
// Color for extra touch
type Color string
const (
Black Color = "\u001b[30m"
Red = "\u001b[31m"
BoldRed = "\u001b[91m"
Green = "\u001b[32m"
BoldGreen = "\u001b[92m"
Yellow = "\u001b[33m"
BoldYellow = "\u001b[93m"
Blue = "\u001b[34m"
BoldBlue = "\u001b[94m"
Reset = "\u001b[0m"
)
// Simplify the color printing
func cprint(color Color, title string, time_value string) {
fmt.Println(string(Yellow), title, string(color), time_value, string(Reset))
}
func main() {
epoch_now := time.Now().Unix()
// cprint(Red, "Now time: ", time.Unix(epoch_now, 0).Format(time.RFC1123Z))
epoch_time := flag.Int64("epoch", epoch_now, "Supply epoch time value")
flag.Parse()
cprint(Red, "Epoch time: ", strconv.FormatInt(*epoch_time, 10))
local_time := time.Unix(*epoch_time, 0).Format(time.RFC1123Z)
cprint(BoldBlue, "Local time: ", local_time)
zulu_time := time.Unix(*epoch_time, 0).UTC().Format(time.RFC1123Z)
cprint(BoldGreen, "Zulu time: ", zulu_time)
}