Home > Net >  How to set IST time in Remote Machine?
How to set IST time in Remote Machine?

Time:08-24

loc, err := time.LoadLocation("Asia/Calcutta") 
if err != nil{
     fmt.Println(err) 
}
now := time.Now().In(loc)
fmt.Println(now)

First I wanted IST time format in my remote machine, But I got the following error, In local machine working fine. The error comes only for Remote Machine*

I got an error:

The system cannot find the path specified.

panic: time: missing Location in a call to Time. In

CodePudding user response:

    //IST  -> UTC   5:30
fixedZone := time.FixedZone("IST", 5*3600 1800)
in := time.Now().In(fixedZone)
log.Println(in)
log.Println(in.Zone())

log.Println("--------------------------")
// my time is UTC 8:00
name, offset := time.Now().Zone()
log.Println(name)
log.Println(offset)

2022/08/24 17:53:35 2022-08-24 15:23:35.0625673  0530 IST
2022/08/24 17:53:35 IST 19800
2022/08/24 17:53:35 --------------------------
2022/08/24 17:53:35 CST
2022/08/24 17:53:35 28800

CodePudding user response:

This generally may happen when the function time.LoadLocation() is called and it looks for a reference for the time zoneinfo and the same is not available on the Remote machine. You should check as to where you are running this program; the Remote machine also contains a valid path for the zoneinfo.zip file .
If you were using this earlier and have recently upgraded to a new version for Go,also update the zoneinfo.zip file to the latest version from the golang repository on the same remote machine as well.
I would also recommend you to check details on Go Package for func LoadLocation.

  • Related