Last active
September 1, 2021 09:08
-
-
Save nicewook/36b9fcbe87d6996483b3500aa5e5fa70 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) | |
dateFormat := "2006-01-02Z07" | |
dateStartInput := "2021-09-01" | |
dateEndInput := "2021-09-01" | |
dateStartAsLocal := fmt.Sprintf("%s%+03d", dateStartInput, offset) | |
dateEndAsLocal := fmt.Sprintf("%s%+03d", dateEndInput, offset) | |
fmt.Println("dateStartAsLocal", dateStartAsLocal) | |
fmt.Println("dateEndAsLocal", dateEndAsLocal) | |
start, _ := time.Parse(dateFormat, dateStartAsLocal) | |
end, _ := time.Parse(dateFormat, dateEndAsLocal) | |
end = end.Add(24 * time.Hour) | |
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