admin
2022-08-25 264b5dea5b74c4b5ba54a90caba7e709858a037e
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package com.yeshi.buwan.util;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Entity;
 
@Entity
public class TimeUtil {
 
    public static String getMonthDay(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("MM.dd");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getHistoryTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getAllTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getAllNoTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getyyyyMMddHHTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getyyyyMMdd(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getAnnoncementTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        String date = sdf.format(new Date(time));
        sdf = new SimpleDateFormat("HH:mm");
        String hm = sdf.format(new Date(time));
        return date + "\n" + hm;
    }
 
    public static String getCommonTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(new Date(time));
        sdf = new SimpleDateFormat("HH:mm");
        String hm = sdf.format(new Date(time));
        return date + "\n" + hm;
    }
 
    public static String getGernalTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getGernalTime(long time, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static long convertGernalTime(String st, String format) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            date = sdf.parse(st);
//            LogUtil.i(date.getTime() + "");
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
 
    public static String getExchangeAdTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
        String date = sdf.format(new Date(time));
        return date;
    }
 
    public static String getCommentTime(long target) {
        target = target / 1000;
        final long dayCut = 2592000L;
        long now = System.currentTimeMillis() / 1000;
        long c = now - target;
        if (c < 60) {
            return "刚刚";
        } else if (c < 60 * 60)
            return c / (60) + "分钟前";
        else if (c < 24 * 60 * 60)
            return c / (60 * 60) + "小时前";
        else if (c < dayCut)
            return c / (24 * 60 * 60) + "天前";
        else if (c < 30 * dayCut)
            return c / (30L * 24 * 60 * 60) + "个月前";
        else
            return c / (12L * 30L * 24 * 60 * 60) + "年前";
    }
 
    // 将标准日期转为时间戳
    public static long convertDateToTemp(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = sdf.parse(st);
            LogUtil.i(date.getTime() + "");
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
 
    // 将标准日期转为时间戳
    public static long convertAllTimeToTemp(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            date = sdf.parse(st);
            LogUtil.i(date.getTime() + "");
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
 
    public static long convertDateToTemp1(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss");
        try {
            date = sdf.parse(st);
            LogUtil.i(date.getTime() + "");
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
 
    public static long convertDateToTemp2(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(st);
            LogUtil.i(date.getTime() + "");
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
 
    public static boolean isSameDay(String time1, String time2) {
        if (getGernalTime(Long.parseLong(time1)).equalsIgnoreCase(getGernalTime(Long.parseLong(time2))))
            return true;
        else
            return false;
    }
}