How to get the current date and time with timestamp in local and other timezones ?
LoadLocation returns the Location with the given name.
Syntax
func LoadLocation(name string) (*Location, error)
Example
package main
import (
"fmt"
"time"
)
func main() {
t := time.Now()
fmt.Println("Location : ", t.Location(), " Time : ", t) // local time
location, err := time.LoadLocation("America/New_York")
if err != nil {
fmt.Println(err)
}
fmt.Println("Location : ", location, " Time : ", t.In(location)) // America/New_York
loc, _ := time.LoadLocation("Asia/Shanghai")
now := time.Now().In(loc)
fmt.Println("Location : ", loc, " Time : ", now) // Asia/Shanghai
}
Output
Location : Local Time : 2017-08-26 21:04:56.1874497 +0530 IST
Location : America/New_York Time : 2017-08-26 11:34:56.1874497 -0400 EDT
Location : Asia/Shanghai Time : 2017-08-26 23:34:56.1884498 +0800 CST
Most Helpful This Week
Get Year, Month, Day, Hour, Min and Second from a specified date
How to declare empty Map in Go?
How to use function from another file golang?
Find out how many logical processors used by current process
Get current date and time in various format in golang
How to Decode or Unmarshal bi-dimensional array of integers?
How to Convert string to float type in Go?
How to append text to a file in Golang?
How to read input from console line?
How to check if a string contains a numbers in Golang?