我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

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?

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.

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

  • https://golang.org/pkg/time/#Parse
  • https://golang.org/pkg/time/#Time.Unix

近期文章

  • 匿名类型声明通过“ var”和“:=”的工作方式不同
  • 在URL golang中传递变量
  • 如何使用指针修改切片
  • 如何在Go中分配16GB内存?
  • golang:读取文件生成器
  • 在Go中设置包路径
  • 为什么golang中的频道需要执行常规程序?
  • 如何在GO中获取指向接口的指针
  • 如何正确使用time.Parse从Unix时间字符串创建时间对象?
  • 为什么我用openssl和golang生成的RSA签名不同?
  • Golang指向值的指针字符串
  • 在GoLang中使用GMT + 2获取当前时间
  • Go中的不可变字符串
  • 复杂的JSON封送处理到GoLang对象
  • 跨多个包共享结构
  • 推迟使用说明
  • 在golang中创建一块缓冲通道
  • 如何确定类型是否是Golang中的结构
  • golang推迟不评估何时预期
  • Golang:检查文件是否为硬链接?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华