• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

转载自:https://www.ohyee.cc/post/note_go_read_openwrt_timezone

运行golang时,Wrt发现打印时间错误。Golang读取时区的过程:

读取TZ环境变量

阅读/etc/localtime文件

使用UTC时间读取本地时区失败。

所以我们可以设置/etc/localtime的时区。但是/etc/localtime文件不是随便写的,需要符合一定的格式。所以安装时区文件:

opkg更新

opkg安装区域信息-亚洲

将时区设置为上海:

ln-SF/usr/share/zoneinfo/Asia/Shanghai/etc/local time

运行代码:

主包装

导入(

' fmt '

系统调用

时间

)

func main() {

t :=时间。现在()。格式(' 2006-01-02 15:04:05 ')

fmt。印刷时间

fmt。Println(时间。本地)

tz,ok :=syscall。Getenv('TZ ')

fmt。Println(tz,ok)

}

你可以看到时间是正确的:

2022-05-02 22:42:28

当地的

错误的

Link to comment
Share on other sites