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() 方法和多语言支持

相关阅读 >>

Golang如何封装路由

Golang 之 struct能不能比较

什么是量化交易|量化交易平台

Go中x/sync/semaphore解读

Go module 12

实用在线工具网站 https://qetool.com

分析Go中的类型比较

Golang如何捕获错误

Golang 中const是什么

关于Golang里的future/promise

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




打赏

取消

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

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

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

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

评论

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