Python時間日期類型

來源:互聯網
上載者:User

標籤:時間類型   時間模組   time模組   

一、 time 模組

Python 程式能用很多方式處理日期和時間,轉換日期格式是一個常見的功能。

1)time是歸類在Generic Operating System Services中,它提供的功能是更加接近於作業系統層面的。time模組是圍繞著Unix Timestamp進行的

 

2)時間戳記是指格林威治時間1970年01月01日00時00分00秒(北京時間1970年01月01日08是00分00秒)起至現在的總秒數,結果是一個浮點數

 

3)所能表述的日期範圍被限定在1970-2038之間

 

import time  # 使用的time模組

print(time.time())

print(type(time.time()))

# 可以完成基本時間處理,列印當前日期或者時間

 

4)什麼是時間元組?

很多Python函數用一個元組裝起來的9組數文書處理時間:


二、datetime模組

1)date 日期對象,常用的屬性有year,month,day

2)time 時間對象,常用的屬性有:hour,minute,second,microsecond

3)datetime 日期時間對象,常用的屬性有year,month,day,hour,minute,second,microsecond

4)timedelta 時間間隔,即兩個時間點之間的長度

5)tzinfo 時區資訊對象

 

import datetime # 使用的datetime模組

print(datetime.datetime.now())

 

執行結果:

C:\python\python.exe C:/python/demo/file3.py

1519800723.2606907

<class 'float'>

2018-02-28 14:52:03.260690

 

Process finished with exit code 0


Python時間日期類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.