个人技术分享

from datetime import datetime

# 获取当前时间
current_time = datetime.now()
print(f"current_time = {current_time}")

# yyyymmdd
format_date = current_time.strftime("%Y%m%d")
print(f"format_date = {format_date}")

# yyyy-mm-dd
format_date = current_time.strftime("%Y-%m-%d")
print(f"format_date = {format_date}")

# yyyy/mm/dd
format_date = current_time.strftime("%Y/%m/%d")
print(f"format_date = {format_date}")

# yy-mm-dd
format_date = current_time.strftime("%y-%m-%d")
print(f"format_date = {format_date}")

# yyyy-mm-dd HH:MM:SS
format_date = current_time.strftime("%y-%m-%d %H:%M:%S")
print(f"format_date = {format_date}")

# yyyy-mmm-dd,  英文月份简称
format_date = current_time.strftime("%Y-%h-%d")
print(f"format_date = {format_date}")

运行结果:

current_time = 2024-05-10 13:21:42.572172
format_date = 20240510
format_date = 2024-05-10
format_date = 2024/05/10
format_date = 24-05-10
format_date = 24-05-10 13:21:42
format_date = 2024-May-10