from datetime import datetime, timedelta, timezoneutc_dt = datetime.utcnow().replace(tzinfo=timezone.utc)print(utc_dt)cn_dt = utc_dt.astimezone(timezone(timedelta(hours=8)))print(cn_dt)jan_dt = utc_dt.astimezone(timezone(timedelta(hours=9)))print(jan_dt)cn_2_jan_dt = cn_dt.astimezone(timezone(timedelta(hours=9)))print(cn_2_jan_dt)
实际上只要datetime的对象存在,就可以使用astimezone的方法转换到任何一个时区