![](/img/trans.png)
[英]Equivalent function in python for MATLAB's lowpass() function?
[英]Equivalent function of MatLab's “dateshift(…)” in Python?
我不確定它是否相同,但是datetime
模塊可以將時間作為timetuple
,並具有用於年,月,日等的單獨組件。這很容易直接操作以前進到下個月,等等。
如果您不介意使用擴展名,請簽出dateutil
。 功能列表開始於:
- 計算相對增量(下個月,明年,下周一,一個月的最后一周等);
dateutil.relativedelta
的文檔顯示了如何升級到各個點。
我認為calendar.monthrange
應該為您做到這一點,例如:
>>> import datetime, calendar
>>> year = int(input("Enter year: "))
Enter year: 2012
>>> month = int(input("Enter month: "))
Enter month: 3
>>> endOfMonthDate = datetime.date(year, month, calendar.monthrange(year, month)[1])
>>> endOfMonthDate
datetime.date(2012, 3, 31)
>>>
您可能會在這里找到其他有用的功能: https : //docs.python.org/2/library/calendar.html和此處: https : //docs.python.org/2/library/datetime.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.