全功能的日期和时间库 [英] Full-featured date and time library

查看:104
本文介绍了全功能的日期和时间库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道一个很好的日期和时间库已经正确实现了以下功能:

I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following:


  • <强>微秒分辨率

  • 夏令时


    • 示例:知道在2009年3月8日美国2:30不存在尊重夏令时间的时区。

    • 我可以指定一个时区,如US /东方,应该足够聪明,知道给定的时间戳是否应该与EST或EDT相对应。

    • Microsecond resolution
    • Daylight savings
      • Example: it knows that 2:30am did not exist in the US on 8 March 2009 for timezones that respect daylight savings.
      • I should be able to specify a timezone like "US/Eastern" and it should be smart enough to know whether a given timestamp should correspond to EST or EDT.

      • 创建在周末和假期跳过的专业商业日历的能力。


      • 定义营业时间的能力,以便在营业时间可以向上或向下舍入到下一个或上一个有效时间。


      • 能够添加和减去所有单位的整数,几个月,几周,几天,几小时,分钟,...)。请注意,添加0.5天的内容没有明确定义,因为它可能意味着12小时,或者意味着一天的持续时间的一半(夏令时不是24小时)。


      • 给定一个时间戳,我希望能够做到像最近的十年,年,月,周,...,四分之一小时,小时等一样的事情。

      我目前使用的是Python,虽然我很高兴有另一种语言的解决方案,如perl,C或C ++

      I'm currently using Python, though I'm happy to have a solution in another language like perl, C, or C++.

      我发现内置的Python库缺乏复杂的夏令时逻辑,并没有一个明显的方法(对我来说)设置东西像自定义时间范围一样。

      I've found that the built-in Python libraries lack sophistication with their daylight savings logic and there isn't an obvious way (to me) to set up things like custom time ranges.

      推荐答案

      Python的标准库的 datetime 限于无争议的方面,这些方面一直没有随着立法规定而改变 - 这就是为什么它故意排除直接支持时区,DST,模糊解析和不明确的算术(例如一个月后...)等等。除此之外, dateutil 可进行多种操作,而 pytz ,添加你要求的大部分内容,虽然不是非常爆炸性的东西,如假期这不同于政治管辖区的差异,甚至在一个模糊的管辖范围内甚至跨雇主(例如在美国,有些雇主认为哥伦布日是一个假期,但是许多人并不是在某些地方设有办事处)它作为一些地方的假期,但不是在其他地方;给予这个完美的混乱,期待找到一个通用的图书馆,以某种方式神奇地使混乱的意义是相当奇怪的)。

      Python's standard library's datetime module is deliberately limited to non-controversial aspects that aren't changing all the time by legislative fiat -- that's why it deliberately excludes direct support for timezones, DST, fuzzy parsing and ill-defined arithmetic (such as "one month later"...) and the like. On top of it, dateutil for many kinds of manipulations, and pytz for timezones (including DST issues), add most of what you're asking for, though not extremely explosive things like "holidays" which vary so wildly not just across political jurisdictions but even across employers within a simgle jurisdiction (e.g. in the US some employers consider "Columbus Day" a holiday, but many don't -- and some, with offices in many locations, have it as a holiday on some locations but not in others; given this utter, total chaos, to expect to find a general-purpose library that somehow magically makes sense of the chaos is pretty weird).

      这篇关于全功能的日期和时间库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆