从特定时间开始按时间戳生成唯一字符串
从特定时间开始按时间戳生成唯一字符串
- 常规字符串a-z,A-Z,0-9一共62个字符串设置为字典
将当前时间与特定时间的时间差,转为时间戳后生成一个62位字符串
def timestampto62(): timestamp_flag = 0 # 特定时间 timestamp = int(datetime.now().timestamp() * 10 ** 6) -timestamp_flag characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" result = "" if timestamp == 0: return characters[0] while timestamp > 0: remainder = timestamp % 62 result = characters[remainder] + result timestamp //= 62 return result