public String getStandardDate(int dateTime) {

        StringBuffer sb = new StringBuffer();

        long t = Long.parseLong(String.valueOf(dateTime));
long time = System.currentTimeMillis() - (t * 1000);
long mill = (long) Math.ceil(time / 1000);//秒前 long minute = (long) Math.ceil(time / 60 / 1000.0f);// 分钟前 long hour = (long) Math.ceil(time / 60 / 60 / 1000.0f);// 小时 long day = (long) Math.ceil(time / 24 / 60 / 60 / 1000.0f);// 天前 long month = (long) Math.ceil(time / 30 / 24 / 60 / 60 / 1000.0f);// 月前 long year = (long) Math.ceil(time / 12 / 30 / 24 / 60 / 60 / 1000.0f);// 年前 Calendar cal = Calendar.getInstance(); long showYear = cal.get(Calendar.YEAR); long showMonth = cal.get(Calendar.MONTH); long showDay = cal.get(Calendar.DATE); long showHour = cal.get(Calendar.HOUR_OF_DAY); long showMint = cal.get(Calendar.MINUTE); if (month - 1 > 0) {
if (month >= 12) {
sb.append(showYear + "." + showMonth + "." + showDay + " " + showHour + ":" + showMint);
} else {
sb.append(month + "个月");
}
} else if (day - 1 > 0) {
if (day >= 30) {
sb.append("1个月");
} else {
sb.append(day + "天");
}
} else if (hour - 1 > 0) {
if (hour >= 24) {
sb.append("1天");
} else {
sb.append(hour + "个小时");
}
} else if (minute - 1 > 0) {
if (minute == 60) {
sb.append("1个小时");
} else {
sb.append(minute + "分钟");
}
} else if (mill - 1 > 0) {
if (mill == 60) {
sb.append("1分钟");
} else {
sb.append(mill + "秒");
}
} else {
sb.append("刚刚");
}
if (month <= 12 && !sb.toString().equals("刚刚")) {
sb.append("前");
}
return sb.toString();
}

Android 将时间戳转为代表"距现在多久之前"的字符串的更多相关文章

  1. js时间戳转为日期格式

    转自:http://wyoojune.blog.163.com/blog/static/57093325201131193650725/ 这个在php+mssql(日期类型为datetime)+aja ...

  2. js 时间戳转为日期格式

    原文:js 时间戳转为日期格式 js 时间戳转为日期格式 什么是Unix时间戳(Unix timestamp): Unix时间戳(Unix timestamp),或称Unix时间(Unix time) ...

  3. 10位时间戳转为C#格式时间

    /// <summary> /// 10位时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></p ...

  4. js实现UTC时间转为北京时间,时间戳转为时间

    用了阿里云的接口,发现其穿的日期是UTC格式的.需要转换. var utc_datetime = "2017-03-31T08:02:06Z"; function utc2beij ...

  5. 时间戳转为C#格式时间

    经常发现很多地方使用一个时间戳表示时间.比如: 1370838759 表示 2013年6月10日 12:32:39. 我们就需要一个工具,方便地转换这种时间格式 什么是时间戳? 时间戳, 又叫Unix ...

  6. Excel中如何将时间戳转为时间?

    Unix时间戳转换Excel时间? Excel中如何将时间戳转为时间? Excel默认不支持Unix格式时间戳,这在导入数据时十分不便.可以用以下公式将时间戳转换成Excel格式的时间: =(x+8* ...

  7. C#关于时间(获取特定格式的时间及多种方式获取当前时间戳)以及10位和13位时间戳转为特定格式

    C#关于时间(获取特定格式的时间及多种方式获取当前时间戳)以及10位和13位时间戳转为特定格式 置顶 2018年03月06日 19:16:51 黎筱曦 阅读数:19098 标签: C#时间 更多 个人 ...

  8. js时间戳转为日期函数

    js时间戳转为日期函数 function add0(m){ return m<10?'0'+m:m; } //timestamp参数示例:1501234567 function format(t ...

  9. Android中时间戳的详细解释

    Android中时间戳的详细解释: (1).定义: 时间戳就是根据当前系统时间生成的一组随机数字. (2).作用: 作为对数据唯一性的一种判断依据.避免了重复修改数据所带来的错误! (3).应用: ( ...

随机推荐

  1. python3.x +django + nginx + uwsgi 搭建web服务

    最近一直在用django开发自己的网站.在开发和线上环境的对接过程中遇到了许多的坑.所以想以一个老鸟的经历来写一下怎么 搭建web服务 一.python3.x .django .nginx .uwsg ...

  2. github上创建ssh连接多个账户

    简单的说用两对ssh密钥来连接多个github账户,有的同学问:用一对连接多个账户行吗?答案是不行,因为密钥和你的账户邮箱关联了. 1.生成密钥. sshkey -t rsa -b 4096 -C & ...

  3. location 设定某个文件的过期时间,并不记录访问日志

    网页的根目录本来是: 6 root /app/www/default; [root@web01 default]# cat /app/server/nginx/conf/vhosts/default. ...

  4. SCWS 中文分词

    SCWS 中文分词v1.2.3 开源免费的中文分词系统,PHP分词的上乘之选! 首页 下载 演示 文档 关于 服务&支持 API/HTTP 论坛 捐赠 源码@github 文档目录 SCWS- ...

  5. 搜索引擎根据原Sphider的脚本修正后的 Sphider-plus 2.2

    搜索引擎根据原Sphider的脚本修正后的 Sphider-plus 2.2 标签: 搜索引擎脚本search数据库authorizationjavascript -- : 1412人阅读 评论() ...

  6. 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.-

    bug: 今天做项目的时候遇到了这样一个崩溃信息: 解决Collection <__NSArrayM: 0xb550c30> was mutated while being enumera ...

  7. [转]C++中的三种继承public,protected,private

    链接:http://www.cnblogs.com/BeyondAnyTime/archive/2012/05/23/2514964.html

  8. ftok函数例子

    #include <stdio.h>#include <sys/types.h>#include <sys/ipc.h>int main( void ){ int ...

  9. RP2837 IN1-IN2 对应关系 2路DI

    RP2837 IN1-IN2 对应关系: IN1   ARM-IO2   PA16 IN2   ARM-IO6   PA4 root@sama5d3-linux:~ echo 16  > /sy ...

  10. linux 驱动cc1101

    cc110x.h /*  * File:   cc110x.h * Author: elinux * * Created on 2015年4月7日, 上午10:32 */ #ifndef CC110X ...