admin
2021-07-28 c0269fcfa876b9c5cf309b2006462b4d09c5ef95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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) + "年前";
    }
 
 
}