【Python】获取当前国内时间(适用于服务器部署在国外的)

 

import datetime
import time
import pytz as pytz

if __name__ == '__main__':
    tz = pytz.timezone('Asia/Shanghai')  # 东八区
    t = datetime.datetime.fromtimestamp(int(time.time()), tz).strftime('%Y-%m-%d %H:%M:%S %Z%z')
    print(t)  # 2021-10-14 21:28:15 CST+0800

 

posted @ 2021-10-14 21:32  淡怀  阅读(533)  评论(0编辑  收藏  举报