douhao6271 2016-01-05 16:06
浏览 203
已采纳

在Go中将日期格式设置为dd_mm_yyyy会产生奇怪的值

So as in the title, I'm trying to format a date in dd_mm_yy format using time.Now().Format("02_01_2006") as shown in this playground session:

http://play.golang.org/p/alAj-OcRZt

First problem, dd_mm_yyyy isn't an acceptable format, only dd_mm_yy is, which is fine I can manipulate the returned string myself.

The problem I have for you is to help me figure out what Go is even trying to do with this input.

You should notice the result you get is:

10_1110009

A good few thousand years off and it's lost the underscore which it only does it for _2. Does this character sequence represent something special here?

Replacing the last underscore with a hyphen or space returns a valid result. dd_mm_yy works fine. Just this particular case seems to completely fly off the handle.

On my local machine (Go playground is on a specific date) the result for today (the 5th) is:

05_01 5016

Which is equally strange, if not moreso as it's substituted in a space which seems to be an ANSIC thing.

  • 写回答

2条回答 默认 最新

  • dongzuan4917 2016-01-05 16:15
    关注

    This is very likely due to the following bug: https://github.com/golang/go/issues/11334

    This has been fixed in Go 1.6beta1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?