美文网首页
优雅的时间格式化方式

优雅的时间格式化方式

作者: 在路上的CT | 来源:发表于2016-06-27 19:47 被阅读21次
/**
 * @param time
 * @return
 * 时间间隔
 */
public static String dayToNow(long time) {
    Calendar now = Calendar.getInstance();
    long minute = (now.getTimeInMillis() - time) / 60000;
    if (minute < 60) {
        if (minute == 0) {
            return "刚刚";
        } else {
            return minute + "分钟前";
        }
    }
    long hour = minute / 60;
    if (hour < 24) {
        return hour + "小时前";
    }
    long day = hour / 24;
    if (day < 30) {
        return day + "天前";
    }
    long month = day / 30;
    if (month < 11) {
        return month + "个月前";
    }
    long year = month / 12;
    return year + "年前";
}

相关文章

  • 优雅的时间格式化方式

  • java DateFormat

    DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间。日期/时间格式化...

  • moment格式化时间

    nodejs中的moment模块可以格式化时间使用: //默认格式化当前时间两种方式

  • Go语言标准库之time

    Go语言标准库之time 时间的格式化和解析 格式化 FormatGo语言和其他语言的时间格式化的方式不同,Go语...

  • Go语言标准库之time

    Go语言标准库之time 时间的格式化和解析 格式化 Format Go语言和其他语言的时间格式化的方式不同,Go...

  • 时间格式化方式

  • 接口文档的编写

    参考资料 如何优雅的格式化接口 如何优雅的“编写”api接口文档 接口文档的编写

  • 时间转换函数moment.js

    moment.js是一款转换时间的插件 安装方式为: 其常用的格式化参数如下表所示: 常用的转换 1.时间格式化 ...

  • 【Python扫盲】字符串格式化

    字符串格式化 Python的字符串格式化有两种方式 %格式符方式 format方式 事实上,格式化借助的是对象的魔...

  • Go语言开发时间格式化

    习惯了IOS时间格式化的方式,在go语言开发的时候,在Go语言开发的时候竟然为格式化时间还查了半天资料,看完资料之...

网友评论

      本文标题:优雅的时间格式化方式

      本文链接:https://www.haomeiwen.com/subject/wuozdttx.html