In the below example – we are implementing apython program to print the current/ today's year, month and year.
在下面的示例中-我们正在实现一个python程序来打印当前/今天的年,月和年。
Steps:
脚步:
Import the date class from datetime module
从datetime模块导入日期类
Create a date object of today's date – call the today() function of date class to get the current date.
创建今天日期的日期对象–调用date类的today()函数以获取当前日期。
By using the date object – we can extract and print today's year, month and day.
通过使用日期对象,我们可以提取和打印今天的年,月和日。
# Python program to# print today's year, month and day# importing the date class datetime modulefrom datetime import date# creating the date object of today's datecurrent_date = date.today() # printing the current dateprint("Current date: ", current_date)# extracting the current year, month and dayprint("Current year:", current_date.year)print("Current month:", current_date.month)print("Current day:", current_date.day)
Output
输出量
Current date: -03-09Current year: Current month: 3Current day: 9
翻译自: /python/program-to-print-todays-year-month-and-day.aspx
如果觉得《Python程序可打印今天的年 月和日》对你有帮助,请点赞、收藏,并留下你的观点哦!