要获取当前时间的北京地区时间戳,可以使用以下Python代码:

import datetime
import pytz

# 获取当前时间
now = datetime.datetime.now()

# 设置时区为北京
beijing_tz = pytz.timezone('Asia/Shanghai')
now_beijing = now.astimezone(beijing_tz)

# 获取时间戳
timestamp = int(now_beijing.timestamp())

print(timestamp)

运行以上代码,将会输出当前时间的北京地区时间戳。

Python获取当前时间北京地区时间戳

原文地址: https://www.cveoy.top/t/topic/qmww 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录