又肝了3天,整理了80个Python DateTime 例子,必须收藏! (9)

Output:

Today: 2018-01-21 Last Monday: 2018-01-15 Coming Monday: 2018-01-22 复制代码 获取当前季度的第一个日期和最后一个日期 from datetime import datetime, timedelta current_date = datetime.now() current_quarter = round((current_date.month - 1) / 3 + 1) first_date = datetime(current_date.year, 3 * current_quarter - 2, 1) last_date = datetime(current_date.year, 3 * current_quarter + 1, 1)\ + timedelta(days=-1) print("First Day of Quarter:", first_date) print("Last Day of Quarter:", last_date) 复制代码

Output:

First Day of Quarter: 2018-01-01 00:00:00 Last Day of Quarter: 2018-03-31 00:00:00

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzppdz.html