python模組--time模組

來源:互聯網
上載者:User

標籤:字串   nbsp   http   oca   code   min   asc   str   ima   

 

1、時間戳記

1 import time2 #------->> 時間戳記3 print(time.time())
1 1525418832.2835853

2、結構化時間

1 #------->>  結構化 時間2 print(time.localtime())3 print(time.gmtime())4 print(time.localtime().tm_mday)
1 time.struct_time(tm_year=2018, tm_mon=5, tm_mday=4, tm_hour=15, tm_min=28, tm_sec=32, tm_wday=4, tm_yday=124, tm_isdst=0)2 time.struct_time(tm_year=2018, tm_mon=5, tm_mday=4, tm_hour=7, tm_min=28, tm_sec=32, tm_wday=4, tm_yday=124, tm_isdst=0)3 4

3、結構化時間轉成 時間戳記

1 #------->> 將結構化時間轉成 時間戳記2 print(time.mktime(time.localtime()))
1 1525418978.0

4、結構化時間轉成 字串時間

1 #------->> 將結構化時間 轉成  字串時間2 print( time.strftime("%Y-%m-%d %X",time.localtime()))  # 後面的時分秒可以用 %X簡化寫3 print( time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
1 2018-05-04 15:30:522 2018-05-04 15:30:52

5、字串時間 轉成 結構化 時間

1 #------->> 將 字串時間 轉成 結構化時間2 print(time.strptime("2018-5-4 16:10:9","%Y-%m-%d %X"))
time.struct_time(tm_year=2018, tm_mon=5, tm_mday=4, tm_hour=16, tm_min=10, tm_sec=9, tm_wday=4, tm_yday=124, tm_isdst=-1)

6、預設的簡單化的字串時間(西方化的形式)

1 print(time.asctime())2 print(time.ctime())
1 Fri May  4 15:32:39 20182 Fri May  4 15:32:39 2018

7、也是類似於字串化的時間

1 import datetime2 print(datetime.datetime.now())
1 2018-05-04 15:33:57.990908

 

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.