dongshipang8094
dongshipang8094
2015-12-08 11:31
浏览 1.1k
已采纳

Golang time.Parse()得到0001-01-01 00:00:00 +0000 UTC [重复]

This question already has an answer here:

This is my code:

t, _ := time.Parse("12/1/2015 12:00:00", "12/8/2015 12:00:00")
fmt.Println(t)

This is the result: 0001-01-01 00:00:00 +0000 UTC

How to get correct the date string?

Thanks!

</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 在这里有答案:

  • 时间 。解析行为 2个答案 \ n

    这是我的代码:

      t,_:= time.Parse(“ 12  / 1/2015 12:00:00“,” 12/8/2015 12:00:00“)
    fmt.Println(t)
       
     
     

    这是 结果: 0001-01-01 00:00:00 +0000 UTC

    如何获取正确的日期字符串?

    谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drtldt55533
    drtldt55533 2015-12-08 11:42
    已采纳

    You need to use the reference timestamp 2006-01-02 15:04:05 for the layout parameter (playground):

    t, _ := time.Parse("1/2/2006 15:04:05", "12/8/2015 12:00:00")
    
    点赞 评论

相关推荐