How golang get the timezone information from linux system

Now i have cross compile the golang for ARM v7. And I found the time in golang is 8 hour later than linux system on arm.

When I use “date” commad, the result is below, which is right

root@TinaLinux:/# date
Tue Jul 25 12:24:57 CST 2017

But in golang program, the result is below:

Code:
a := time.Now()
fmt.Println(a)
Result:
2017-07-25 04:17:35.689998326 +0000 UTC

I think maybe golang can’t get the correct timezone information from my linux system on ARM v7.
Does everyone know how the mechanism for golang getting timezone information from linux system?

Does the result change if you do

fmt.Println(a.Local())?

instead?

If this still prints UTC, I would guess that Go reads the kernel’s timezone (which appears to be UTC in this case), whereas date uses the current user’s timezone.

Another test:

fmt.Println(a.Zone())
1 Like

When i use the code below:

	a := time.Now()
	fmt.Println(a)
	fmt.Println(a.Local())
	fmt.Println(a.Zone())

The result is

2017-07-28 10:32:06.448536909 +0000 UTC

2017-07-28 10:32:06.448536909 +0000 UTC

UTC 0

I think it shoule be the go can’t get the correct timezone information from my linux system.

Do you know what is the go mechanism for getting time information from linux system?

If it were a timezone-issue, it should result in a full hour shift, I believe. But you have a fuzzy deviation of 8 hours, 7 minutes and some seconds. Perhaps it is a matter of the missing realtime clock in the raspberry Pi? I would try to fix it on OS-Level by installing the “fake-hwclock”-package for example.

Please have a look here: https://raspberrypi.stackexchange.com/questions/4370/where-does-the-raspberry-pi-get-the-time-from

Good luck!

It is my mistake .i haven’t executed the go program and shell command at the same time. I just put the go result and shell result here for 8 hours different information only.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.