2016-01-05 16:06
浏览 185


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:

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:


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.

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

因此,正如标题中一样,我正在尝试使用time.Now()将日期格式化为dd_mm_yy。 格式(“ 02_01_2006”),如以下操场上的会话所示:

第一个问题,dd_mm_yyyy是不可接受的格式,只有dd_mm_yy是,这很好 可以自己操作返回的字符串。

我为您带来的问题是帮助我弄清楚Go甚至试图使用此输入做什么。 < p>您应该注意到得到的结果是:


好几千年了,它已经丢失了 下划线,仅适用于_2。 这个字符序列在这里代表什么特殊之处吗?

用连字符或空格代替最后一个下划线会返回有效结果。 dd_mm_yy工作正常。


05_01 5016

同样令人奇怪的是,它所替代的空间似乎是ANSIC。< / p>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzuan4917 2016-01-05 16:15

    This is very likely due to the following bug:

    This has been fixed in Go 1.6beta1

    解决 无用
    打赏 举报
  • dporu02280 2016-01-05 16:15

    Found an issue from their github:

    Basically _2 is taking the 2 as the day value from the reference time and then trying to parse the rest (006) which it doesn't recognise so it all goes wrong from there.

    解决 无用
    打赏 举报

相关推荐 更多相似问题