提交项目

This commit is contained in:
huangzhuanghua
2016-04-25 11:18:59 +08:00
commit 3f29f7b39a
660 changed files with 68059 additions and 0 deletions

View File

@ -0,0 +1,43 @@
package com.gh.common.util;
public class TimestampUtils {
// 基准时间
private static final long BASE = 1426608000000L;
/*
* 根据CD获取时间戳
*/
public static long getTimestamp(int cd) {
long now = System.currentTimeMillis();
return (long) (Math.ceil((now - BASE) / cd) * cd + BASE);
}
/*
* 为url添加timestamp
*/
public static String addTimestamp(String url, int cd) {
if (url.contains("?")) {
return url + "&timestamp=" + getTimestamp(cd);
} else {
return url + "?timestamp=" + getTimestamp(cd);
}
}
/*
* 去除url中的timestamp
*/
public static String removeTimestamp(String url) {
int index = url.lastIndexOf("timestamp");
String params = url.substring(index);
//连接符
String connector = url.substring(index - 1, index);
String key = url.substring(0, index - 1);
index = params.indexOf("&");
if (index != -1) {
key = key + connector + params.substring(index + 1);
}
return key;
}
}