carbon 是一个轻量级、语义化、对开发者友好的 golang 时间处理库,支持链式调用。
目前已被 awesome-go 收录,如果您觉得不错,请给个 star 吧
github.com/golang-module/carbon
gitee.com/golang-module/carbon
安装使用
Golang 版本大于等于1.16
// 使用 github 库
go get -u github.com/golang-module/carbon/v2
import (
"github.com/golang-module/carbon/v2"
)
// 使用 gitee 库
go get -u gitee.com/golang-module/carbon/v2
import (
"gitee.com/golang-module/carbon/v2")
Golang 版本小于1.16
// 使用 github 库
go get -u github.com/golang-module/carbon
import (
"github.com/golang-module/carbon"
)
// 使用 gitee 库
go get -u gitee.com/golang-module/carbon
import (
"gitee.com/golang-module/carbon"
)
更新日志
- 新增
Time2Carbon
的别名方法FromStdTime,
Carbon2time
的别名方法ToStdTime
,未来将弃用Time2Carbon
和Carbon2
方法 - 修复
Format
方法里W
和N
符号输出错误的 bug - 修复文档描述错误
有疑问加站长微信联系(非本文作者)

提一个建议
文档json编解码这里,需要将 carbon.Carbon 转 carbon.DateTime,文档是carbon.Date{carbon.Now()},但是这么写编辑器会报红,必须写完整 carbon.DateTime{Carbon: carbon.Now()},这么写实在太麻烦了。
能加个转换的方法吗? 类似:
我考虑下如何优化