python time模組

來源:互聯網
上載者:User

標籤:

import time

1、表示時間的類。表示的時間範圍為1970年1月1日到2038年1月19號。

2、python中,表示時間的方式有:1)時間戳記:timestamp

                                        2)格式化的字串

                                        3)元組:struct_time

3、time的函數

1)time.localtime([secs]):將一個時間戳記轉換為當前時區的struct_time。secs參數為空白時,以目前時間為準。

屬性(Attribute)的值(Values)分別為:

月:1-12;日:1-31;時:0-23;分:0-59;秒:0-61;星期:0-6;

天(tm_yday:一年中的第幾天):1-366;夏時令(tm_isdst:是否是夏時令):-1,0(預設為-1)

2)time.time():返回目前時間戳

3)time.mktime(ts):將一個struct_time轉化為時間戳記

4)time.asctiem([ts]):把一個表示時間的元組或者struct_time表示為這種形式:‘Sun Jun 20 14:34:09:2015’。

                                 若參數為空白,則將time.localtime()作為參數傳入

 

5)time.ctime([psec]):把一個時間戳記(按秒計算的浮點數)轉化為time.asctime()的形式,參數為空白時,預設time.time()為參數,相當於time.asctime(time.localtime(secs))

   

 6)time.strptime(str,fmt=‘%a%b%d%H:%M%S%Y‘):根據fmt的格式把一個時間字串解析為時間元組

python time模組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.