duangai1368 2018-04-10 11:06
浏览 79
已采纳

如何用go time解析外文日期字符串

So my problem is: I want to do this:

datestring := "19. april 2018"

parsedDate, err := time.Parse("2. January 2006", datestring)
if err != nil {
    fmt.Println(err)
}

fmt.Println(parsedDate)

This snippet works perfectly... but now my input datestring isn't english... it's german. So april fooled me. (German April = English April). Running this with datestring := "19. Februar 2018" fails:

parsing time "12. februar 2018" as "2. January 2006": 
    cannot parse "februar 2018" as "Januar\"

Is there any way to add parseable (natural) languages? Or define the language I expect. I didn't find any mention of this in the documentation.

Thanks!

  • 写回答

2条回答 默认 最新

  • dourunlao1642 2018-04-10 11:35
    关注

    I believe what you are trying to achieve can be accomplished using the package

    https://godoc.org/github.com/goodsign/monday

    It allows you to specify that you want to parse the date in the German locale using the ParseInLocation function.

    A good example on how to use this (and in german) can be seen in this question.

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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料