TimeUtils

来源:互联网 发布:基于标记的分水岭算法 编辑:程序博客网 时间:2024/05/22 22:33
public class TimeUtil {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);}}


 

原创粉丝点击