JavaScript getTimezoneOffset() method in Golang

378 views Asked by At

In JavaScript we can use this method to get the offset zone.

function myFunction() {
    var d = new Date();
    var n = d.getTimezoneOffset();
    document.getElementById("demo").innerHTML = n;

}

For example , if we are in Berlin , Germany we return -120 minutes. If we are in London we have -60 minutes.

I need exactly that method in golang. Exists??? Thanks to every one.

1

There are 1 answers

0
Not_a_Golfer On

The time.Time type has what you're looking for:

zone, offset := time.Now().Zone()

zone the the timezone name, and offset is its UTC offset. Pretty simple

Example on the playground: http://play.golang.org/p/Ij-TuuRX_K