package com.hanju.video.app.util;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
/**
|
* Created by Administrator on 2016/7/12.
|
*/
|
public class TimeUtil {
|
public static long getTimeStamp(String dateStr, String formate) {
|
Date date = new Date();
|
SimpleDateFormat sdf = new SimpleDateFormat(formate);
|
try {
|
date = sdf.parse(dateStr);
|
return date.getTime();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return 0;
|
}
|
|
public static String getDescString(long time) {
|
final long dayCut = 2592000000L;
|
long now = System.currentTimeMillis();
|
long c = now - time;
|
if (c < 60 * 1000) {
|
return "刚刚";
|
} else if (c < 60 * 60 * 1000L)
|
return c / (60 * 1000L) + "分钟前";
|
else if (c < 24 * 60 * 60 * 1000L)
|
return c / (60 * 60 * 1000L) + "小时前";
|
else if (c < dayCut)
|
return c / (24 * 60 * 60 * 1000L) + "天前";
|
else if (c < 12 * dayCut)
|
return c / (30 * dayCut) + "月前";
|
else
|
return c / (12 * 30 * dayCut) + "年前";
|
}
|
|
|
}
|