import re

目前創(chuàng)新互聯(lián)建站已為千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、柳江網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
def command_add(date, event_details, calendar):
'''
Add event_details to the list at calendar[date]
Create date if it was not there
:param date: A string date formatted as "YYYY-MM-DD"
:param event_details: A string describing the event
:param calendars: The calendars database
:return: a string indicating any errors, "" for no errors
'''
try:
p = re.compile(r"\d{4}-\d{2}-\d{2}")
assert p.match(date), "Param date must match YYYY-MM-DD"
assert isinstance(event_details, str), \
"Param event_details must be a string"
if date in calendar:
calendar[date].append(str(event_details))
else:
calendar.update({date: str(event_details)})
except Exception,e:
return str(e)
def main():
calendar = {}
command_add("2015-10-20", "Python class", calendar)
print calendar
command_add("2015-11-01", "go out with friends after test",
calendar)
print calendar
if __name__ == "__main__":
main()
直接使用python?calender模塊即可。
calendar.calendar(year,w=2,l=1,c=6)
返回一個(gè)多行字符串格式的year年年歷,3個(gè)月一行,間隔距離為c。?每日寬度間隔為w字符。每行長(zhǎng)度為21*?W+18+2*?C。l是每星期行數(shù)。 ?
2. calendar.firstweekday(?)
返回當(dāng)前每周起始日期的設(shè)置。默認(rèn)情況下,首次載入caendar模塊時(shí)返回0,即星期一。
3. calendar.isleap(year)
是閏年返回True,否則為false。
4. ?calendar.leapdays(y1,y2)
返回在Y1,Y2兩年之間的閏年總數(shù)。
5. calendar.month(year,month,w=2,l=1)
返回一個(gè)多行字符串格式的year年month月日歷,兩行標(biāo)題,一周一行。每日寬度間隔為w字符。每行的長(zhǎng)度為7*?w+6。l是每星期的行數(shù)。
6. calendar.monthcalendar(year,month)
返回一個(gè)整數(shù)的單層嵌套列表。每個(gè)子列表裝載代表一個(gè)星期的整數(shù)。Year年month月外的日期都設(shè)為0;范圍內(nèi)的日子都由該月第幾日表示,從1開始。
7. calendar.monthrange(year,month)
返回兩個(gè)整數(shù)。第一個(gè)是該月的星期幾的日期碼,第二個(gè)是該月的日期碼。日從0(星期一)到6(星期日);月從1到12。
8. calendar.prcal(year,w=2,l=1,c=6)
相當(dāng)于?print?calendar.calendar(year,w,l,c).
9. calendar.prmonth(year,month,w=2,l=1)
相當(dāng)于?print?calendar.calendar(year,w,l,c)。
10. calendar.setfirstweekday(weekday)
設(shè)置每周的起始日期碼。0(星期一)到6(星期日)。
11. calendar.timegm(tupletime)
和time.gmtime相反:接受一個(gè)時(shí)間元組形式,返回該時(shí)刻的時(shí)間輟(1970紀(jì)元后經(jīng)過的浮點(diǎn)秒數(shù))。
12. calendar.weekday(year,month,day)
返回給定日期的日期碼。0(星期一)到6(星期日)。月份為?1(一月)?到?12(12月)。
python系統(tǒng)提供了下面常用的函數(shù):
1. 數(shù)學(xué)庫(kù)模塊(math)提供了很多數(shù)學(xué)運(yùn)算函數(shù);
2.復(fù)數(shù)模塊(cmath)提供了用于復(fù)數(shù)運(yùn)算的函數(shù);
3.隨機(jī)數(shù)模塊(random)提供了用來生成隨機(jī)數(shù)的函數(shù);
4.時(shí)間(time)和日歷(calendar)模塊提供了能處理日期和時(shí)間的函數(shù)。
注意:在調(diào)用系統(tǒng)函數(shù)之前,先要使用import 語句導(dǎo)入 相應(yīng)的模塊
該語句將模塊中定義的函數(shù)代碼復(fù)制到自己的程 序中,然后就可以訪問模塊中的任何函數(shù),其方 法是在函數(shù)名前面加上“模塊名.”。
希望能幫到你。
網(wǎng)頁名稱:python+日歷函數(shù),python的日期函數(shù)
鏈接地址:http://chinadenli.net/article25/dseipci.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、標(biāo)簽優(yōu)化、云服務(wù)器、外貿(mào)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)