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


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

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()方法


相关阅读 >>

Go语言 if…else 语句

Golang 定时器详解

关于Golang slice的append扩容

slice

写在 dubbo Go 的第五个年头

Go 为什么比php性能高

Go语言适合做哪些开发

Go 语言和 java 比较?

如何在linux上运行第一个Go程序

Golang基础-高级数据结构

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




打赏

取消

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

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

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

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

评论

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