From aaedcb881b79234ced5df7190c9c847c4f2ee773 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Wed, 4 Mar 2026 00:36:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0createHexTime?= =?UTF-8?q?=E5=92=8CparseHexTime=E5=87=BD=E6=95=B0=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=A4=84=E7=90=86=E5=8D=81=E5=85=AD=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/oauth/oauth.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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