package main
import (
"fmt"
"time"
"strings"
)
func main() {
fmt.Println("Hello World!")
value := "04/19/16, 05:47PM"
biggerTime := "05/19/16, 11:30PM"
// Writing down the way the standard time would look like formatted our way
layout := "01/02/06, 03:04PM"
t1, _ := time.Parse(layout, value)
t2, _ := time.Parse(layout, biggerTime)
duration := t2.Sub(t1)
fmt.Println(duration)
fmt.Println(reformatDuration(duration))
}
func reformatDuration(d time.Duration) string {
stringValue := d.String()
splitHour := strings.Split(stringValue, "h")
var (
hour = "0"
minute = "0"
)
if len(splitHour) > 1 {
hour = splitHour[0]
stringValue = splitHour[1]
}
splitMinute := strings.Split(stringValue, "m")
if len(splitMinute) > 1 {
minute = splitMinute[0]
}
return fmt.Sprintf("%v:%v", hour, minute)
}