时间处理类

来源:互联网 发布:大数据营销系统源码 编辑:程序博客网 时间:2024/06/11 08:43
package com.android.util;import java.text.SimpleDateFormat;import java.util.Date;/** * 转化微博发表时间 */public class BlogTimeUtil {public static String converTime(long timestamp) {long currentSeconds = System.currentTimeMillis() / 1000;// 与现在时间相差秒数long timeGap = currentSeconds - timestamp;String timeStr = null;if (timeGap > 24 * 60 * 60) {// 1天以上timeStr = timeGap / (24 * 60 * 60) + "天前";} else if (timeGap > 60 * 60) {// 1小时-24小时timeStr = timeGap / (60 * 60) + "小时前";} else if (timeGap > 60) {// 1分钟-59分钟timeStr = timeGap / 60 + "分钟前";} else {// 1秒钟-59秒钟timeStr = "刚刚";}return timeStr;}public static String getStandardTime(long timestamp) {SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");Date date = new Date(timestamp * 1000);sdf.format(date);return sdf.format(date);}}