search

Home  >  Q&A  >  body text

java - 如何把时间转换为几天前,几小时前这种格式

我记得有个函数可以转换。

更新

这个问题我自己可以解决。
只是印象中我知道某个库的函数封装了这个功能,希望知道的同学来回答。

问这个问题不是为了投机取巧,不想动手。
也不想打着"不要重复制造轮子"的口号逃避问题。
我只是想找到当初见到的那个轮子。

大家讲道理大家讲道理2767 days ago449

reply all(10)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 13:27:15

    After looking through the code from a long time ago, I finally found it.
    Not in the java sdk, it's in the Android SDK.

    Thank you everyone for sharing.

    import android.text.format.DateUtils;

    DateUtils.getRelativeTimeSpanString(...)

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:27:15

    There is no ready-made function, wouldn’t it be easy to write one yourself?

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:27:15

    You can actually solve this problem by yourself. If you put it here, you guys really don’t want to answer it. It’s not of good quality


    You can search for java time different on Google and attach the link: java time different
    Or search java time difference on Baidu.

    I won’t post the specific code.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:27:15

    I don’t know about Android, but if you are interested in writing it yourself, you can refer to the Moment.js source code of javascript.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:27:15

    There is no ready-made function like this in jdk, nor does it seem to be available in commonly used toolkits. For this kind of problem, you can first google, Baidu, Baidu search results
    google search results, bring your own ladder

    reply
    0
  • 阿神

    阿神2017-04-17 13:27:15

    Just use moment, a js module: momentjs, the format function inside is very powerful

    reply
    0
  • PHPz

    PHPz2017-04-17 13:27:15

    The current timestamp is in seconds.
    Subtract 60s60m24h*(day)

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:27:15

    You are so lazy~ Write it down by yourself, it will be quick.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:27:15

    http://www.zuidaima.com/share/1562038902000640.htm

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:27:15

    You are probably talking about Timeago...
    It should be quite common for those doing web development.

    Either this
    https://github.com/kevinsawicki/java-timeago

    reply
    0
  • Cancelreply