Golang time - 时区显示两次 [英] Golang time - time zone showing twice

查看:32
本文介绍了Golang time - 时区显示两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此代码时,结果应显示日期时间和区域

On running this code the result should show date time and zone

令人惊讶的是,结果显示了两次时区,但我无法弄清楚原因

Surprisingly the result shows time zone twice and am not able to figure out why

package main

import (
    "fmt"
    "time"
)

func main() {

    mytime, _ := time.Parse("02/Jan/2006:15:04:05 -0700", "07/Apr/2017:01:26:05 +0530")

    fmt.Println(mytime)

}

输出是

2017-04-07 01:26:05 +0530 +0530

所以我的问题是为什么时区显示两次?

So my question is why timezone showing twice ?

推荐答案

fmt.Println 调用了 Time.String() 以下列格式返回时间的函数:

The fmt.Println invokes the Time's .String() function that returns the time in the following format:

"2006-01-02 15:04:05.999999999 -0700 MST"

如您所见,其中包含时区偏移量和时区名称.

Which as you see contains both the timezone offset and the timezone name.

在您的情况下,该时间没有已知的时区名称,因此它会输出两次偏移量.

In your case there is no timezone name known for the time, so it outputs the offset twice.

参考文献:

这篇关于Golang time - 时区显示两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆