Answer the question
In order to leave comments, you need to log in
How to get 'Europe/Moscow' time zone as '3h'?
I apologize in advance for such a lammer question, but alas, I can not find a solution that I would like.
I want to get the offset from UTC for a timezone in the format '3h', 3 or at least '+03.00' but I can't seem to find an easy way to do it.
That is, the input data is a time zone as a string (for example, 'Europe/Moscow' , 'Asia/Yekaterinburg' ).
I want to get '3h' and '5h' respectively from these strings. as?
Answer the question
In order to leave comments, you need to log in
I see this option, through time formatting
https://play.golang.org/p/7qLhhuiWmWE
package main
import (
"fmt"
"log"
"time"
)
func main() {
location, err := time.LoadLocation("Europe/Moscow")
if err != nil {
log.Fatal(err)
}
in := time.Now().In(location)
fmt.Println(in.Format("Z07:00"))
fmt.Println(in.Format("-0700"))
fmt.Println(in.Format("Z07"))
fmt.Println(in.Format("-07"))
}
// Вывод:
// +03:00
// +0300
// +03
// +03
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question