自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Pyhon DateTime模塊的常用例子解析

開發(fā) 后端
以下的文章是通過介紹Pyhon DateTime模塊的具體例子來介紹Pyhon DateTime模塊的具體應用方案,如果你想了解其的具體常用例子,你可以點擊我們的文章。

如果你對Pyhon DateTime模塊在實際應用方案不是很了解的話,也不知道Pyhon DateTime模塊的具體例子的應用形式,以下的文章就是對其具有典型例子的相關介紹,希望你會有所收獲。

Pyhon DateTime模塊的常用例子

  1. <!--[if !supportLists]-->1、 <!--[endif]--> 

計算兩個指定時間之間相差的時間值方面

  1. Demo1:   
  2. import datetime  
  3. d1 = datetime.datetime(2005,12,31)  
  4. d2 = datetime.datetime(2004,12,31)  
  5. print (d1 - d2).days   

 輸出:

  1. 365 

 Demo2: 返回一段程序執(zhí)行的時間

  1. import datetime,time  
  2. begin = datetime.datetime.now()  
  3. time.sleep(5)  
  4. begins = datetime.datetime.now()  
  5. print "time is ",(begins - begin).seconds   

 輸出:5

Demo3: 返回一個時間差值的另一個時間點

  1. import datetime,time  
  2. begin = datetime.datetime.now()  
  3. print begin  
  4. d3begin + datetime.timedelta(hours = 2)  
  5. print d3  

 輸出:表示相隔兩個小時的時間值Demo4: 時間與字符類型相互轉換

  1. import datetime,time  
  2. dt_obj = datetime.datetime(2008, 11, 10, 17, 53, 59)  
  3. date_str = dt_obj.strftime("%Y-%m-%d %H:%M:%S")  
  4. print date_str   

輸出:

  1. 2008-11-10 17:53:59 

PS:可以實現(xiàn)格式化輸出一段時間值!以上的文章就是對Pyhon DateTime模塊的常用例子的介紹。

【編輯推薦】

  1. Python編程語言的實現(xiàn)內(nèi)幕的相關介紹
  2. Python數(shù)據(jù)結構如何進行內(nèi)建詳解
  3. 對python腳本語言在實際應用的優(yōu)點介紹
  4. 對Python編程語言歷史發(fā)展的介紹
  5. Python矩陣轉置的實際應用操作方案與代碼詳解

 

責任編輯:佚名 來源: 博客園
相關推薦

2010-03-18 11:25:12

Pyhon DateT

2023-12-22 08:38:02

Pythondatetimetime

2015-07-14 10:13:29

2024-11-19 09:00:00

Pythondatetime模塊

2011-05-23 16:50:12

python

2022-08-16 13:19:18

PythonDatetime時間

2010-03-22 15:38:46

Python常用模塊

2023-03-08 07:33:33

2023-12-07 11:01:27

Python常用模塊內(nèi)置模塊

2010-03-12 15:13:41

Python常用模塊

2010-03-22 10:27:28

Python常用模塊I

2024-11-01 10:30:05

2024-05-28 00:00:10

Python模塊開發(fā)

2022-11-09 19:02:10

Linux

2009-12-15 15:55:43

Ruby模塊

2022-11-22 13:00:38

2010-03-23 17:05:24

Python目錄

2020-08-10 15:35:14

Excel函數(shù)數(shù)據(jù)

2010-07-06 09:48:34

六大UML圖

2010-11-15 15:51:55

Oracle ERP系
點贊
收藏

51CTO技術棧公眾號