Python 日期时间处理、错误码及文件 I/O 操作详解
1. 时区定义与日期时间解析
1.1 时区定义示例
在 Python 中,我们可以自定义时区。以下是一个基本的时区定义原型:
# Variables that must be defined
# TZOFFSET - Timezone offset in hours from UTC. For
# example, US/CST is -6 hours
# DSTNAME - Name of timezone when DST is in effect
# STDNAME - Name of timezone when DST not in effect
class SomeZone(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=TZOFFSET) + self.dst(dt)
def dst(self, dt):
# is_dst() is a function you must implement to see
# whether DST is in effect according to local timezone rules.
if is_dst(dt):
return datetime.timedelta(hours=1)
else:
return date
超级会员免费看
订阅专栏 解锁全文
2万+

被折叠的 条评论
为什么被折叠?



