国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現計算兩個時間之間相差天數的方法

2019-11-25 16:11:28
字體:
來源:轉載
供稿:網友

本文實例講述了Python實現計算兩個時間之間相差天數的方法。分享給大家供大家參考,具體如下:

#-*- encoding:UTF-8 -*-from datetime import dateimport timenowtime = date.today()def convertstringtodate(stringtime):  "把字符串類型轉換為date類型"  if stringtime[0:2] == "20":    year=stringtime[0:4]    month=stringtime[4:6]    day=stringtime[6:8]    begintime=date(int(year),int(month),int(day))    return begintime  else :    year="20"+stringtime[0:2]    month=stringtime[2:4]    day=stringtime[4:6]    begintime=date(int(year),int(month),int(day))    return begintimedef comparetime(nowtime,stringtime):  "比較兩個時間,并返回兩個日期之間相差的天數"  if isinstance(nowtime,date):    pass  else:    nowtime=convertstringtodate(nowtime)  if isinstance(stringtime,date):    pass  else:    stringtime=convertstringtodate(stringtime)  result=nowtime-stringtime  return result.days"""  if stringtime[0:2] == "20":    year=stringtime[0:4]    month=stringtime[4:6]    day=stringtime[6:8]    begintime=date(int(year),int(month),int(day))    endtime=nowtime    result=endtime-begintime    return result.days  else :    year="20"+stringtime[0:2]    month=stringtime[2:4]    day=stringtime[4:6]    begintime=date(int(year),int(month),int(day))    endtime=nowtime    result=endtime-begintime    return result.days"""print isinstance("20141012",date)print comparetime(nowtime,"140619")

PS:這里再為大家推薦幾款關于日期與天數計算的在線工具供大家使用:

在線日期/天數計算器:
http://tools.VeVB.COm/jisuanqi/date_jisuanqi

在線萬年歷日歷:
http://tools.VeVB.COm/bianmin/wannianli

在線陰歷/陽歷轉換工具:
http://tools.VeVB.COm/bianmin/yinli2yangli

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python日期與時間操作技巧總結》、《Python URL操作技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 招远市| 松潘县| 安阳县| 西丰县| 隆安县| 汉川市| 刚察县| 东丽区| 大安市| 万荣县| 平果县| 延川县| 阜宁县| 文成县| 建德市| 大石桥市| 黔南| 谢通门县| 洪湖市| 平邑县| 隆化县| 宽城| 阳谷县| 蒲江县| 伊春市| 公安县| 易门县| 宁夏| 古交市| 济宁市| 富宁县| 绥阳县| 集安市| 礼泉县| 乌鲁木齐市| 武穴市| 平罗县| 平度市| 尼勒克县| 延津县| 东乡县|