Print Current Date in Python

You can print the current date in Python using the datetime module.

import datetime

# 获取当前日期
current_date = datetime.date.today()

# 打印当前日期
print(current_date)

When running the above code, the current date will be printed in the format of YYYY-MM-DD.

If you only want to print a part of the date, such as the year, month, or day, you can use the year, month, and day attributes.

import datetime

# 获取当前日期
current_date = datetime.date.today()

# 打印年份
print(current_date.year)

# 打印月份
print(current_date.month)

# 打印日期
print(current_date.day)

Running the above code will print out the year, month, and date of the current date separately.

bannerAds