简体   繁体   English

如何在python日期时间模块中自定义hr、month、year?

[英]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.

相关问题 如何从“年”,“日期”,“月”,“时间”列中生成unix时间列,最好使用python的pandas模块 - How to generate a unix time column from “year”,“date”,“month”,“time” columns, preferrably using pandas module for python Python将日期/时间拆分为月,日期,年,时间列 - Python Spliting Date/Time into Month, Date, Year, Time columns 如何从 python 中的日期中提取年份和月份 - How to extract year and month from date in python 如何在 python 中获取带有年份和月份的月份的第一个和最后一个日期 - How to get the first and last date of the month with Year and Month in python 将日期(月、日、年、时间)转换为 python 中的日期时间格式 - Convert date (month, day, year, time) to Datetime format in python 在Python中为日期时间使用Groupby时出现问题。 如何用月/年制作条形图? - Problem using Groupby in Python for date time. How to make a bar plot with Month/Year? 如何删除年月日,仅在 python 上显示时间 - How do I delete year month and date, display only time on python Python datetime - 当时间&gt; 1小时时有2种日期格式的列为(H:M:S),当时间&lt;1小时时为(M:S) - 如何解析 - Python datetime - column with 2 date formats being (H:M:S) when time >1 hr, and (M:S) when time <1 hr - how to parse 如何从python中的datetime系列中删除Year-Month-Date? - How to drop the Year-Month-Date from a datetime series in python? 如何通过在python中仅输入一年中的某一天获得相关的月份和日期 - How to get relevant month and date by inputting only the day of year in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM