时间函数
当地时间
import time
time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
from datetime import datetime
time = datetime.now().strftime("%H:%M:%S")
时间运用
from datetime import datetime, timedelta
today = datetime.now()
print(today)
last_month_date = datetime(today.year, today.month, 1) - timedelta(days=1)
print(last_month_date)
dt = int(last_month_date.strftime('%Y%m%d'))
print(dt)
now = today.strftime('%Y%m%d')
print(now)
#结果
2023-04-18 09:48:09.015491
2023-03-31 00:00:00
20230331
20230418