go-carbon 1.3.1 版本发布,新增 DiffForHumans() 方法和多语言支持


本文摘自网络,作者,侵删。

carbon 是一个轻量级、语义化、对开发者友好的Golang时间处理库,支持链式调用、农历和gorm、xorm等主流orm

如果您觉得不错,请给个star吧

github:github.com/golang-module/carbon

gitee:gitee.com/go-package/carbon

carbon.Now().DiffForHumans()) // just now
carbon.Now().SubYears(1).DiffForHumans()) // 1 years ago
carbon.Now().SubYears(2).DiffForHumans()) // 2 year ago
carbon.Now().AddYears(1).DiffForHumans()) // in 1 year
carbon.Now().AddYears(2).DiffForHumans()) // in 2 years
// 对人类友好的可读格式时间差(指定语言)
carbon.Now().SetLocale("zh-CN").DiffForHumans()) // 刚刚
carbon.Now().SubMonths(1).SetLocale("zh-CN").DiffForHumans()) // 1 月前
carbon.Now().AddMonths(2).SetLocale("zh-CN").DiffForHumans()) // 2 月后

更新日志

  • 新增DiffForHumans()方法,获取对人类友好的可读格式时间差
  • 新增SetLocale()方法,设置语言包
  • 新增Locale()方法,获取当前语言包
  • 新增英文语言包lang/en.js
  • 新增简体中文语言包lang/zh-CN.js
  • 新增繁体中文语言包lang/zh-TW.js
  • 优化Format()方法

本文来自:Segmentfault

感谢作者:.container .card .information strong

查看原文:go-carbon 1.3.1 版本发布,新增 DiffForHumans() 方法和多语言支持

相关阅读 >>

Go微服务入门到容器化实践,落地可观测的微服务电商项目

Golang使用protobuf中的oneof

prometheus实战---告警模板编写(四)

Golang之sync.pool对象池对象重用机制总结

Golang怎么判断数组是否为空

关于 Go 并发编程之 mutex

在使用database/sql时应避免掉进这11个坑 !(Go 数据库)

Golang用户登录怎么做

Golang如何设置字体

Go语言 continue 语句

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...