中讨论了一些时间函数 第一组
null
还可以使用Python使用“datetime”模块和其中的“Date”类来执行日期操作。
截止日期:
1.明年 :-它显示 最低年份 可以使用date类来表示。
2.MAXYEAR :-它显示 最长年份 可以使用date类来表示。
# Python code to demonstrate the working of # MINYEAR and MAXYEAR # importing built in module datetime import datetime from datetime import date # using MINYEAR to print minimum representable year print ( "Minimum representable year is : " ,end = "") print (datetime.MINYEAR) # using MAXYEAR to print maximum representable year print ( "Maximum representable year is : " ,end = "") print (datetime.MAXYEAR) |
输出:
Minimum representable year is : 1 Maximum representable year is : 9999
3.日期(年月日) :-此函数返回一个字符串,其中包含按年、月和日期顺序传递的参数。
4.今天 :-返回 今日 格式为yyyy-mm-dd。
# Python code to demonstrate the working of # date() and today() # importing built in module datetime import datetime from datetime import date # using date() to represent date print ( "The represented date is : " ,end = "") print (datetime.date( 1997 , 4 , 1 )) # using today() to print present date print ( "Present date is : " ,end = "") print (date.today()) |
输出:
The represented date is : 1997-04-01 Present date is : 2016-08-02
5.fromtimestamp(秒) :-它返回 从秒开始计算的日期 从争论中提到的时代起就已经过去了。
6.min() :-这将返回 最短日期 可以用date类来表示。
7.max() :-这将返回 最长日期 可以用date类来表示。
# Python code to demonstrate the working of # fromtimestamp(), min() and max() # importing built in module datetime import datetime from datetime import date # using fromtimestamp() to calculate date print ( "The calculated date from seconds is : " ,end = "") print (date.fromtimestamp( 3452435 )) # using min() to print minimum representable date print ( "Minimum representable date is : " ,end = "") print (date. min ) # using max() to print minimum representable date print ( "Maximum representable date is : " ,end = "") print (date. max ) |
输出:
The calculated date from seconds is : 1970-02-09 Minimum representable date is : 0001-01-01 Maximum representable date is : 9999-12-31
本文由 曼吉星 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END