TSW1985
TSW1985

Reputation: 1329

JavaScript getTimezoneOffset() method in Golang

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.

Upvotes: 0

Views: 377

Answers (1)

Not_a_Golfer
Not_a_Golfer

Reputation: 49265

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

Upvotes: 1

Related Questions