时间|日期|时间加减法|神器
import time # ------------- 输出皆为字符串 ---------- import pendulum time_format_pattern = "%Y-%m-%d %H:%M:%S" # 字符格式 pendulum_from_timestamp = pendulum.from_timestamp(time.time()) # 通过时间戳转化成pendulum格式 print(f"pendulum_from_timestamp : {pendulum_from_timestamp} {type(pendulum_from_timestamp)}") today_time = pendulum.now().strftime(time_format_pattern) # 获取当前时间 print(f"today_time : {today_time} {type(today_time)}") add_today_time = pendulum.now().add(days=10).strftime(time_format_pattern) # 10天以后 print(f"add_today_time : {add_today_time} {type(add_today_time)}") subtract_today_time = pendulum.now().subtract(days=10).strftime(time_format_pattern) # 10天以前 print(f"subtract_today_time : {subtract_today_time} {type(subtract_today_time)}") add_today_time = pendulum.now().add(months=10).strftime(time_format_pattern) # 10月以后 print(f"add_today_time : {add_today_time} {type(add_today_time)}") subtract_today_time = pendulum.now().subtract(months=10).strftime(time_format_pattern) # 10月以前 print(f"subtract_today_time : {subtract_today_time} {type(subtract_today_time)}")
-----------------------------------------------------------------------------------------------------------------------------------------