Skip to content

Instantly share code, notes, and snippets.

@ealebed
Created July 17, 2022 08:56
Show Gist options
  • Save ealebed/2b10df7b4e32653bd6ca48e0b8f6886f to your computer and use it in GitHub Desktop.
Save ealebed/2b10df7b4e32653bd6ca48e0b8f6886f to your computer and use it in GitHub Desktop.
Count time to date/time in future
package main
import (
"fmt"
"time"
)
func main() {
loc, _ := time.LoadLocation("Europe/Kiev")
now := time.Now().In(loc)
futureDate := time.Date(2022, time.August, 5, 13, 41, 0, 0, loc)
fmt.Println("\nCurrent time:", now)
fmt.Printf("======================================================\n")
fmt.Println("Meeting day time:", futureDate)
fmt.Printf("======================================================\n")
diff := futureDate.Sub(now)
days := int(diff.Hours() / 24)
fmt.Printf("Time to hugs in days: %d days\n", days)
hrs := int(diff.Hours())
fmt.Printf("Time to hugs in hours: %d Hours\n", hrs)
mins := int(diff.Minutes())
fmt.Printf("Time to hugs in minutes: %d Minutes\n", mins)
second := int(diff.Seconds())
fmt.Printf("Time to hugs in seconds: %d Seconds\n", second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment