Show correct datetime in relation to time zone

This commit is contained in:
dtonon
2024-05-29 22:33:22 +02:00
parent 7a422da589
commit cae76d1168
5 changed files with 35 additions and 9 deletions

View File

@@ -478,3 +478,19 @@ func clamp(val, low, high int) int {
}
return val
}
func getUTCOffset(loc *time.Location) string {
// Get the offset from UTC
_, offset := time.Now().In(loc).Zone()
// Calculate the offset in hours
offsetHours := offset / 3600
// Format the UTC offset string
sign := "+"
if offsetHours < 0 {
sign = "-"
offsetHours = -offsetHours
}
return fmt.Sprintf("UTC%s%d", sign, offsetHours)
}