博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python程序可打印今天的年,月和日
阅读量:2532 次
发布时间:2019-05-11

本文共 987 字,大约阅读时间需要 3 分钟。

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 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:  2020-03-09Current year: 2020Current month: 3Current day: 9

翻译自:

转载地址:http://eixzd.baihongyu.com/

你可能感兴趣的文章
原生和jQuery的ajax用法
查看>>
iOS开发播放文本
查看>>
20145202马超《java》实验5
查看>>
JQuery 事件
查看>>
main(argc,argv[])
查看>>
源码:Java集合源码之:哈希表(二)
查看>>
【HDU 3709】 Balanced Number (数位DP)
查看>>
JsonPath的使用
查看>>
企业常用的站内收索、QQ群、在线客服
查看>>
Centos下安装nginx步骤解析
查看>>
EntityFramework Code First 添加唯一键
查看>>
在线教育工具—白板系统的迭代1——bug监控排查
查看>>
招行ODC项目表彰
查看>>
js补充知识点-label应用
查看>>
给构造函数(constructor)创建对象(object)
查看>>
局域网访问PHP项目网站 用IP地址进入
查看>>
VM虚拟机,Linux系统安装tools过程遇到 what is the location of the “ifconfig” program
查看>>
Jquery实现循环删除Reaper某一行
查看>>
脚本升级openssh
查看>>
linux学习(3)——vim文本编辑工具
查看>>