go-durationfmt - a Go library for customizing duration formatting

blov · · 404 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey all,</p> <p>I wrote a library called <a href="https://github.com/davidscholberg/go-durationfmt" rel="nofollow">go-durationfmt</a> that allows you to format <a href="https://golang.org/pkg/time/#Duration" rel="nofollow">durations</a> according to a format string.</p> <p>For example, if you had a <code>time.Duration</code> value equal to 42,000 minutes, and you wanted to format it in the same way that the unix <a href="https://linux.die.net/man/1/uptime" rel="nofollow">uptime</a> command displays durations, you can specify the format string <code>%d days, %0h:%0m</code>, and go-durationfmt would output <code>29 days, 04:00</code>. See the <a href="https://github.com/davidscholberg/go-durationfmt#duration-format" rel="nofollow">Duration Format</a> section of the README for a complete description of the format string rules.</p> <p>I am aware that <a href="https://github.com/hako/durafmt" rel="nofollow">durafmt</a> and <a href="https://github.com/dustin/go-humanize" rel="nofollow">go-humanize</a> provide similar functionality, but as far as I can tell, they don&#39;t allow you to customize the output with a format string.</p> <p>I am also aware that the assumption that days are always 24 hours and years are always 365 days is not always correct. I cover this in the <a href="https://github.com/davidscholberg/go-durationfmt#caveats" rel="nofollow">Caveats</a> section of the README.</p> <p>Feedback is welcome. Thank you for your time.</p>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

404 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传