android 将时间戳转为代表"距现在多久之前"的字符串
2012-06-27 10:54
363 查看
/** * 将时间戳转为代表"距现在多久之前"的字符串 * @param timeStr 时间戳 * @return */ public static String getStandardDate(String timeStr) { StringBuffer sb = new StringBuffer(); long t = Long.parseLong(timeStr); 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);// 天前 if (day - 1 > 0) { 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 (!sb.toString().equals("刚刚")) { sb.append("前"); } return sb.toString(); }
相关文章推荐
- android 将时间戳转为代表"距现在多久之前"的字符串
- android 将时间戳转为代表"距现在多久之前"的字符串
- Android 将时间戳转为代表"距现在多久之前"的字符串
- android将时间戳转为代表”距现在多久之前”的字符串
- "超时时间已到。在操作完成之前超时时间已过或服务器未响应"的解决方法
- 字符串反转 "you are beautiful" 转为 "beautiful are you"
- android时间工具--多久之前
- 字符串反转 "you are beautiful" 转为 "beautiful are you" 方法二 更为简单
- "超时时间已到。在操作完成之前超时时间已过或服务器未响应"的解决方法
- "超时时间已到。在操作完成之前超时时间已过或服务器未响应"的解决方法
- Android 根据时间戳转换成多久之前
- "超时时间已到。在操作完成之前超时时间已过或服务器未响应"的解决方法
- Android 开发之 SimpleDateFormat 类解析&输出指定格式的日期时间字符串
- 升级IE弹出"以前的安装有尚未完成的操作,需要重新启动。建议在运行Internet Explorer安装程序之前重新启动计算机。现在安装程序将关闭"
- Android 时间转换为多久之前
- UE4:Android调试部署到手机时,提示"输入字符串不正确"
- OC语言——传入时间与现在时间 差距 60 秒以内,输出@"刚刚" 以此类推
- PHP中"多少时间之前的"做法
- Android 关于从后台获得时间的字符串转为日期格式再变成字符串
- iOS 准确计算某个时间点距现在的时间差的代码 如"几分钟,几小时,几秒之前" ,