[英]how to customized hr,month,year in python date time module?
How can i customize hrs,days,months of date time module in python?如何在python中自定义日期时间模块的小时、天、月? day of 5 hrs only, a month of 20 days only, and a year of 10 months only.
一天只有5小时,一个月只有20天,一年只有10个月。 using date time module.
使用日期时间模块。
I agree with @TimPeters .我同意@TimPeters。 This just doesn't fit in what datetime does.
这不符合 datetime 的作用。
For your needs, I would be inclined to start my own class from scratch, as that is pretty far from datetime.根据您的需要,我倾向于从头开始我自己的课程,因为这与日期时间相差甚远。
That said...you could look into monkeypatching datetime...but I would recommend against it.也就是说......你可以研究monkeypatching datetime......但我建议不要这样做。 It's a pretty complex beast, and changing something as fundamental as the number of hours in a day will blow away unknown assumptions within the code, and would certainly turn its unit tests upside down.
这是一个非常复杂的野兽,改变像一天中的小时数这样基本的东西会破坏代码中的未知假设,并且肯定会颠倒它的单元测试。
Build your own from scratch is my advice.从头开始构建你自己是我的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.