当前位置: 动力学知识库 > 问答 > 编程问答 >

python - What's the difference between pytz.utc and dt.timezone.utc?

问题描述:

I am writing a library and I don't want to require pytz since the library itself doesn't know or care about timezones (it's reading and writing data in the form of Unix timestamps, which don't have any timezone information associated with them). I always return new timestamps as aware datetimes using dt.timezone.utc (i.e. something like dt.datetime(..., tzinfo=dt.timezone.utc)).

Will these timestamps interact sensibly (e.g. datetime subtraction produces correct results) with pytz timestamps like those you get from pytz.localize(...), or do I need to use pytz.utc instead?

网友答案:

It is ok to use datetime.timezone.utc. You don't need to use pytz.utc, only to cooperate with pytz timezones.

utc timezone has a fixed utc offset (zero, always). Such tzinfo objects should work with any tzinfo implementations.

分享给朋友:
您可能感兴趣的文章:
随机阅读: