Python中文
首页
教程
问答
标签
搜索
登录
注册
Python中有没有一种处理month的方法与Java中处理YearMonth的方法相同?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>作为一个Java开发人员,如果我必须处理monthes(compare、increment、delta…),我将使用<a href="https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/time/YearMonth.html" rel="nofollow noreferrer">YearMonth</a>类。 今天我用Python编写代码,我在寻找一些类似的东西</p> <p>我看了<a href="https://docs.python.org/3/library/datetime.html" rel="nofollow noreferrer">https://docs.python.org/3/library/datetime.html</a>和<a href="https://docs.python.org/3/library/calendar.html" rel="nofollow noreferrer">https://docs.python.org/3/library/calendar.html</a>没有发现像YearMonth的东西</p> <p>我想我得处理日历了</p> <p>我可能错过了什么</p> <p>目标:</p> <ul> <li>提供计算两个月之间的月增量的方法</李> <li>能够在日期/日期时间之间进行转换</李> <li>将其与日期或日期时间进行比较</李> <li>作为编组/解编组的表示(这是要点)</li> </ul> <p>我希望我有几个月的例子:</p> <pre class="lang-py prettyprint-override"><code>dt1 = datetime(2019,12,31,23,59,59) dt2 = datetime(2020,1,1,1,1,1) ym1 = yearmonth(dt1) ym2 = yearmonth(dt2) ym_delta = ym2-ym1 </code></pre> <p>ym_delta(或ym_delta.months)应等于1</p> <pre class="lang-py prettyprint-override"><code>ym1 = yearmonth(2018,12) ym2 = yearmonth(2020,1) ym_delta = ym2-ym1 </code></pre> <p>ym_delta(或ym_delta.months)应等于13</p> <p>我希望有几个月的时间。 此库: <a href="https://pythonhosted.org/MonthDelta/" rel="nofollow noreferrer">https://pythonhosted.org/MonthDelta/</a> 接近我的搜索</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>获取月份的一个简单选项是使用time.localtime() 例如</p> <pre><code>import time date=time.localtime() year=date[0] month=date[1] day=date[2] hour=date[3] minute=date[4] seconds=date[5] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何添加虚拟方法
5 回答
如何添加表示整数的擦边字符串?
1 回答
如何添加要在Bokeh中使用的新font.ttf文件?
7 回答
如何添加要显示的矩阵XY轴编号和XY轴
3 回答
如何添加计数?
9 回答
如何添加计数器函数?
7 回答
如何添加计数器列来计算数据帧中另一列中的特定值?
9 回答
如何添加计数器来跟踪while循环中的月份和年份?
9 回答
如何添加计数并删除countplot的顶部和右侧脊椎?
5 回答
如何添加计时器wx.应用程序更新窗口对象的主循环?
5 回答
如何添加评论到帖子?PostDetailVew,Django 2.1.5
3 回答
如何添加评论拉梅尔亚姆
9 回答
如何添加诸如矩阵Python/Pandas之类的数据帧?
6 回答
如何添加谷歌地点自动完成到Flask?
6 回答
如何添加超时、python discord bot
3 回答
如何添加超过1dp的检查
8 回答
如何添加距离方法
3 回答
如何添加跟随游戏的敌人精灵
1 回答
如何添加路径以便python可以找到程序?
6 回答
如何添加身份验证/安全性以使用happybase访问HBase?
5 回答