Skip to content

Golang lib that converts from GPS coordinate latitude/longitude to timezone string.

License

Notifications You must be signed in to change notification settings

Lionparcel/timezonemapper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timezonemapper

Golang lib that converts from GPS coordinate latitude/longitude to timezone string.

Translated from java version, see https://github.com/drtimcooper/LatLongToTimezone .

Install

go get -u github.com/Lionparcel/timezonemapper

Usage

package main

import (
	"fmt"
	"github.com/Lionparcel/timezonemapper"
	"time"
)

func main() {
	// Get timezone string from lat/long
	timezone := timezonemapper.LatLngToTimezoneString(39.9254474,116.3870752)
	// Should print "Timezone: Asia/Shanghai"
	fmt.Printf("Timezone: %s\n", timezone)
	// Load location from timezone
	loc, _ := time.LoadLocation(timezone)
	// Parse time string with location
	t, _ :=time.ParseInLocation("2006-01-02 15:04:05", "2010-01-01 00:00:00", loc)
	// Should print
	// 2010-01-01 00:00:00 +0800 CST
	// 2009-12-31 16:00:00 +0000 UTC
	fmt.Println(t)
	fmt.Println(t.UTC())
}

Map update

Last updated at 2019.10.22

Will update (I guess) if the original project drtimcooper/LatLongToTimezone updates.

About

Golang lib that converts from GPS coordinate latitude/longitude to timezone string.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%