提交项目
This commit is contained in:
43
app/src/main/java/com/gh/common/util/TimestampUtils.java
Normal file
43
app/src/main/java/com/gh/common/util/TimestampUtils.java
Normal 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 + "×tamp=" + 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user