Python Date & Time
1. time module
1 2 3 4 5 6 7 | import time time.time() #The function time.time() returns the current system time in ticks since 12:00am, January 1, 1970(epoch). time.asctime([tupletime]) #Accepts a time-tuple and returns a readable 24-character string such as 'Tue Dec 11 18:07:14 2008'. time.localtime([secs]) #Accepts an instant expressed in seconds since the epoch and returns a time-tuple t with the local time (t.tm_isdst is 0 or 1, depending on whether DST applies to instant secs by local rules). |
2. calendar module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import calendar calendar.calendar(year,w = 2 ,l = 1 ,c = 6 ) #Returns a multiline string with a calendar for year #year formatted into three columns separated by c spaces. #w is the width in characters of each date; each line has length 21*w+18+2*c. #l is the number of lines for each week. calendar.firstweekday( ) #Returns the current setting for the weekday that starts each week. #By default, when calendar is first imported, this is 0, meaning Monday. calendar.isleap(year) #Returns True if year is a leap year; otherwise, False. calendar.month(year,month,w = 2 ,l = 1 ) #Returns a multiline string with a calendar for month month of year year, #one line per week plus two header lines. #w is the width in characters of each date; each line has length 7*w+6. #l is the number of lines for each week. |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步