2015-05-07 16:15 阅读 251


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);

    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:

    点赞 评论 复制链接分享