Python 获取当前时间戳并增加 101 分钟
将当前 13 位时间戳加上 101 分钟的时间戳,可以进行如下操作:
- 将 13 位时间戳转换为 datetime 对象。
- 使用 timedelta 对象增加 101 分钟。
- 将增加后的时间转换为 13 位时间戳。
下面是 Python 代码实现:
import datetime
# 获取当前时间的 13 位时间戳
current_timestamp = int(datetime.datetime.now().timestamp() * 1000)
# 转换为 datetime 对象
current_time = datetime.datetime.fromtimestamp(current_timestamp / 1000)
# 增加 101 分钟
updated_time = current_time + datetime.timedelta(minutes=101)
# 转换为 13 位时间戳
updated_timestamp = int(updated_time.timestamp() * 1000)
print(updated_timestamp)
请注意,这个代码假设当前的 13 位时间戳是以毫秒为单位的。如果当前时间戳是以秒为单位的,需要将代码中的 '* 1000' 和 '/ 1000' 去除。
原文地址: https://www.cveoy.top/t/topic/oyua 著作权归作者所有。请勿转载和采集!