Last active
September 1, 2021 10:12
-
-
Save nicewook/ab8ecb1a843cc90adce016d421339689 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"fmt" | |
"time" | |
) | |
// local time calculation | |
func main() { | |
currentTime := time.Now() | |
zone, offset := currentTime.Zone() | |
offset /= 3600 | |
fmt.Printf("current timezone %v, offset as hour %v\n", zone, offset) | |
timeFormat := "2006-01-02T15:04:05Z07" | |
timeStartInput := "03:00:00" | |
timeEndInput := "19:12:00" | |
timeStartAsLocal := fmt.Sprintf("%d-%02d-%02dT%s%+03d", currentTime.Year(), int(currentTime.Month()), currentTime.Day(), timeStartInput, offset) | |
timeEndAsLocal := fmt.Sprintf("%d-%02d-%02dT%s%+03d", currentTime.Year(), int(currentTime.Month()), currentTime.Day(), timeEndInput, offset) | |
fmt.Println("timeStartAsLocal", timeStartAsLocal) | |
fmt.Println("timeEndAsLocal", timeEndAsLocal) | |
start, _ := time.Parse(timeFormat, timeStartAsLocal) | |
end, _ := time.Parse(timeFormat, timeEndAsLocal) | |
end = end.Add(1 * time.Second) | |
fmt.Println("start:", start.Format(time.RFC3339)) | |
fmt.Println("end:", end.Format(time.RFC3339)) | |
fmt.Println(start, end) | |
fmt.Println(time.Now().After(start)) | |
fmt.Println(time.Now().Before(end)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment