diff --git a/src/auth/oauth/oauth.ts b/src/auth/oauth/oauth.ts index 285afcd..0121ec5 100644 --- a/src/auth/oauth/oauth.ts +++ b/src/auth/oauth/oauth.ts @@ -449,3 +449,25 @@ export class OAuth { return id; } } + +/** + * 长度为8位的时间的十六进制字符串,单位为秒,使用createHexTime创建,使用parseHexTime解析 + * @param date + * @returns + */ +export const createHexTime = (date: Date) => { + const timestamp = Math.floor(date.getTime() / 1000); + const hex = timestamp.toString(16); + return hex; +}; + +/** + * 解析createHexTime创建的十六进制时间字符串,返回Date对象 + * @param hex + * @returns + */ +export const parseHexTime = (hex: string) => { + const timestamp = parseInt(hex, 16); + const date = new Date(timestamp * 1000); + return date; +}; \ No newline at end of file