dongshan8953
2015-05-07 16:15 阅读 251
已采纳

golang:将日期和时间转换为秒

If I have date format: "1/_2/2006, 15:04:05"

How to I convert the entire date to seconds. Is there a golang time method?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doubiaokai4998 doubiaokai4998 2015-05-07 16:22

    There's a nice little package on GitHub to abstract the format matching part of Parse (it requires you provide a string to explain the format of your date); https://github.com/araddon/dateparse

    You can just use ParseAny to get a time.Time{} call it ts then ts.Unix to get seconds. I would recommend it since Parse itself is extremely sensitive to it's input.

    点赞 评论 复制链接分享
  • douniewei6346 douniewei6346 2015-05-07 16:17

    You can use time.Parse and then call Unix on the result:

    点赞 评论 复制链接分享

相关推荐