自动人类可读的时间间隔 [英] Automatic human readable time interval

查看:135
本文介绍了自动人类可读的时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想前preSS一些的时间间隔在人类可读的格式。我一直在寻找能够自动选择单位的正确尺寸的图书馆。间隔范围从毫秒到几周。类似

I would like to express some time intervals in a human readable format. I was looking for a library automatically able to choose the correct size of the units. The intervals will range from milliseconds to weeks. Something like


  • 0.2秒

  • 2:00

  • 4天

  • ...

我知道我可以手动检查参数的大小,然后将其转换,但重新发明轮子之前,我想问问,如果有一个(标准)库来实现这一目标。

I know I could manually check the size of the argument and then convert it but before reinventing the wheel I wanted to ask if there is a (standard) library to achieve that.


  • 的TimeUnit 做的转换但没有对参数的大小
  • 知识
  • 乔达时的时间重新presents正是我需要的,但我没有找到很多关于重新presentation(但的ISO8601格式< A HREF =htt​​p://www.joda.org/joda-time/apidocs/org/joda/time/ReadableDuration.html相对=nofollow> ReadableDuration )

  • TimeUnit does the conversions but there is no knowledge about the size of the argument
  • a Joda-Time Duration represents exactly what I need but I did not find much about representation (but for the ISO8601 formatting of ReadableDuration)

修改

我在纳秒的输入和输出,如上所述。

My input in in nanoseconds and output as described above.

推荐答案

prettyTime

prettyTime是一个开放源代码的时间格式化库。完全可定制,prettyTime创建像看到在Digg,Twitter和Facebook的人可读,相对时间戳。这很简单,上手现在!,并在超过18种语言!

PrettyTime is an OpenSource time formatting library. Completely customizable, PrettyTime creates human readable, relative timestamps like those seen on Digg, Twitter, and Facebook. It’s simple, get started "right now!" and in over 18 languages!

例如:

    PrettyTime p = new PrettyTime();
    System.out.println(p.format(new Date()));
    //prints: "right now"

    PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L));
    t.format(new Date(0));
    //3 centuries ago 

这篇关于自动人类可读的时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆