python DST 和 GMT 管理到调度程序中
我打算用 python 编写一个调度程序应用程序,但我不会 处理 DST 和 GMT 时遇到麻烦。
例如,另请参阅PHP 相关问题 563053。
有人已经在做类似的事情了吗?
有人已经体验过 PyTZ - Python 时区库吗?
I'm planning to write a sheduler app in python and I wouldn't
be in trouble with DST and GMT handling.
As example see also PHP related question 563053.
Does anyone worked already on something similar?
Does anyone already experienced with PyTZ - Python Time Zone Library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,我们中的许多人都从事过日历/调度程序的工作,并且熟悉 pytz。您的具体问题是什么,在您指出的 SO 问题和 ITS 答案/评论中尚未得到很好的回答...?
编辑:因此,如果您按照其他问题的最佳答案中的建议进行操作,则不会出现特殊的陷阱。特别是,在内部对 UTC 进行标准化(“GMT”是一个古老的术语和概念),并在 I/O 上与时区(带 DST 和 c)进行转换(就像您应该在内部对 Unicode 进行标准化并进行编码/解码一样)如果必须的话,只能在 I/O 上转换为字节!-)。
Python 标准库中有一个简单而灵活的模块,名为 sched,它提供了一个可配置的“事件调度程序”,并且可能是您应用程序的核心,在 日历 的帮助下, datetime 等 Python 的“时间和金钱”章节中的一些秘诀Cookbook,第二版,可能会有所帮助(它作为在线盗版广泛存在,尽管作为合著者我不一定喜欢这个事实;-)。
如果不知道自己在写什么——Web 服务、Web 应用程序、桌面应用程序或其他任何东西,就很难说更多。您想支持vCal,iCalendar, vCalendar ,其他形式的互操作/同步/混搭,如果是的话,还有哪些其他应用程序、服务和/或事实上的标准?等等——就像所有应用程序一样,如果它被证明是成功的,它当然可以不断成长;-)。
Sure, many of us have worked on calendars / schedulers and are familiar with pytz. What's your specific question, that's not already well answered in the SO question you point to and ITS answers / comments...?
Edit: so there are no special, particular pitfalls if you do things as recommended in the best answers to the other question. In particular, do standardize on UTC internally ("GMT" is an antediluvian term and concept) and convert to/from timzones (w/DST &c) on I/O (just as you should standardize on Unicode internally and encode/decode to bytes, if you must, only on I/O!-).
There's a simple and flexible module in the Python standard library called sched which provides a configurable "event scheduler" and might be at the core of your app, with help from calendar, datetime etc. Some of the recipes in the "Time and Money" chapter of the Python Cookbook, 2nd ed, may help (it's widely available as online pirate copies, though as a co-author I don't necessarily LIKE that fact;-).
It's hard to say much more without having any idea of what you're writing -- web service, web app, desktop app, or whatever else. Do you want to support vCal, iCalendar, vCalendar, other forms of interop/sync/mashup and if so with what other apps, services and/or de facto standards? Etc, etc -- like all apps, it can grow and grow if it proves successful, of course;-).
pytz 效果很好。请务必将您的时间转换并存储为 UTC,并使用 pytz/datetime 转换例程转换为本地时间。有一个使用和时区转换的示例 这里,基本上:
pytz works great. Be sure to convert and store your times as UTC and use the pytz/datetime conversion routines to convert to local time. There's an example of usage and timezone conversion here, basically: