获取当年第一天/最后一天的日期对象 [英] Get date object for the first/last day of the current year
本文介绍了获取当年第一天/最后一天的日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取当年第一天和最后一天的 date
个对象。
I need to get date
objects for the first and last day in the current year.
当前我正在使用此代码,效果很好,但我很好奇是否有更好的方法可以做到;例如
Currently I'm using this code which works fine, but I'm curious if there's a nicer way to do it; e.g. without having to specify the month/day manually.
from datetime import date
a = date(date.today().year, 1, 1)
b = date(date.today().year, 12, 31)
推荐答案
想到的唯一真正的改进就是为变量赋予比 a
和<$ c更多的描述性名称$ c> b 。
The only real improvement that comes to mind is to give your variables more descriptive names than a
and b
.
这篇关于获取当年第一天/最后一天的日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文