小编use*_*424的帖子

使用pytz进行python错误的时区转换

我在python中编写了以下脚本,将datetime从任何给定的时区转换为EST.

from datetime import datetime, timedelta  
from pytz import timezone  
import pytz  
utc = pytz.utc  

# Converts char representation of int to numeric representation '121'->121, '-1729'->-1729 
def toInt(ch):  
    ret = 0  
    minus = False  
    if ch[0] == '-':  
        ch = ch[1:]  
        minus = True  
    for c in ch:  
        ret = ret*10 + ord(c) - 48  
    if minus:  
        ret *= -1  
    return ret  

# Converts given datetime in tzone to EST. dt = 'yyyymmdd' and tm = 'hh:mm:ss' 
def convert2EST(dt, tm, …
Run Code Online (Sandbox Code Playgroud)

python timezone pytz

2
推荐指数
1
解决办法
2327
查看次数

标签 统计

python ×1

pytz ×1

timezone ×1