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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题