编写一个 Python 程序来获取当前日期和时间,并附带示例。例如,在此编程语言中,我们有一个 datetime 模块来处理或打印当前日期和时间,它将显示输出。
from datetime import date
today = date.today()
print("Current Date = ", today)
Current Date = 2021-11-06
在此 示例 中,我们使用了 datetime now 来打印当前日期和时间,并使用了 strftime 来格式化。
from datetime import datetime
today = datetime.now()
print("Current Date and Time = ", today)
# Formatting
dt = today.strftime("%B %d, %Y %H:%M:%S")
print("Current Date and Time = ", dt)
