python的time模組

來源:互聯網
上載者:User

標籤:localtime   單位   運行   fse   rom   lock   val   imp   strftime   

 1 #encoding=utf-8 2 import time 3  4 # 返回時間戳記 5 print time.time() 6  7 # 延遲運行單位為s,如下為延遲3s 8 time.sleep(3) 9 10 # 轉換時間戳記為時間元組(時間對象),自1970+second,其second為秒數11 print time.gmtime(4)12 13 # 轉換時間戳記為本機物件14 print time.localtime()15 16 # 將時間戳記轉換為字串17 print time.asctime(time.localtime())18 19 # 將時間戳記轉換為字串20 print time.ctime(5)21 22 # 將本地時間轉換為時間戳記23 t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)24 print time.mktime(t)25 26 # 將時間對象轉換為規範性字串(常用),格式如下27 ‘‘‘28 %Y Year with century as a decimal number.29 %m Month as a decimal number [01,12].30 %d Day of the month as a decimal number [01,31].31 %H Hour (24-hour clock) as a decimal number [00,23].32 %M Minute as a decimal number [00,59].33 %S Second as a decimal number [00,61].34 %z Time zone offset from UTC.35 %a Locale‘s abbreviated weekday name.36 %A Locale‘s full weekday name.37 %b Locale‘s abbreviated month name.38 %B Locale‘s full month name.39 %c Locale‘s appropriate date and time representation.40 %I Hour (12-hour clock) as a decimal number [01,12].41 %p Locale‘s equivalent of either AM or PM.42 ‘‘‘43 print time.strftime(‘%Y-%m-%d %H-%M-%S‘,t)44 45 # 將時間字串根據指定的格式化符轉換成數組形式的時間46 struct_time = time.strptime("30 Nov 00", "%d %b %y")47 print struct_time

 

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.