MatLabは、日付を取って、dateshift(...)
functionを使って月、四半期などの終わりに移動できます。PythonのMatLabの "dateshift(...)"と同等の機能ですか?
Pythonに相当する機能はありますか?
MatLabは、日付を取って、dateshift(...)
functionを使って月、四半期などの終わりに移動できます。PythonのMatLabの "dateshift(...)"と同等の機能ですか?
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
を