1 package com.cgcyiliao.admin.util;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5
6 public class DateUtil {
7 /**
8 * 暂定token有效时长7天
9 */
10 private static long TOKEN_EFFECTIVE_TIME = (((1000 * 60) * 60) * 24) * 7;// 7天有效期
11
12 /**
13 * 将时间戳转为指定格式的long类型
14 *
15 * @return
16 */
17 public static String getStringTimeLong(Long dateLong) {
18 if (Util.isEmpty(dateLong)) return "";
19 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
20 Date date = new Date(dateLong);
21 String dateTime = "";
22 try {
23 dateTime = simpleDateFormat.format(date);
24 } catch (Exception e) {
25
26 }
27 return dateTime;
28 }
29
30 /**
31 * 获取当前的时间戳
32 * @return
33 */
34 public static long getNowTime() {
35 return new Date().getTime();
36 }
37
38 /**
39 * 根据token时间获取有效时长的时间戳
40 *
41 * @return
42 */
43 public static long getTokenExceedTime() {
44 return getExceedTime(TOKEN_EFFECTIVE_TIME);
45 }
46
47 private static long getExceedTime(long effectiveTime) {
48 return getNowTime() + effectiveTime;
49 }
50 }