Python程序可打印今天的年,月和日

In the below example – we are implementing a python 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 module
from datetime import date

# creating the date object of today's date
current_date = date.today() 

# printing the current date
print("Current date: ", current_date)

# extracting the current year, month and day
print("Current year:", current_date.year)
print("Current month:", current_date.month)
print("Current day:", current_date.day)

Output

输出量

Current date:  2020-03-09
Current year: 2020
Current month: 3
Current day: 9


翻译自: https://www.includehelp.com/python/program-to-print-todays-year-month-and-day.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值