Python學習_time模組使用

來源:互聯網
上載者:User

標籤:int   學習   string   src   lock   utc   strftime   自訂   時間   

#!/usr/bin/python

#-*- encoding=UTF-8 -*-

#DATE:2018-05-12


"""%y  兩位元的年份00-99%Y 四位元的年份000-9999%m 月份01-12%d   日01-31%H  小時(24小時制即0~23點)%I    小時(12小時制01~12)%M  分鐘%S   秒"""
print(‘====小結====‘)print(‘一、time模組‘)time.time() #擷取目前時間的時間戳記time.gmtime()#擷取國際即UTC的格式化時間(tm_year=2018,tm_mon=5 ……),也可以將時間戳記變為struc_time時間time.localtime()#擷取本地時間的格式化時間(struct_time)# 註:# 格式化時間便於我們知道目前時間是本周或本年的第幾天# 時間戳記一般用於計算時間差time.strftime(format=‘‘,p_tuple=‘‘)#將struc_time格式化為自訂格式的時間#print(time.strftime(‘%Y-%m-%d %H%M%S‘,time.localtime()))# #2018-05-12 092320time.strptime(string=‘‘,format=‘‘)#將特定時間,格式化為格式化時間struc_time#print(time.strptime(‘2018/05/10‘,‘%Y/%m/%d‘))# #time.struct_time(tm_year=2018, tm_mon=5, tm_mday=10, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=130, tm_isdst=-1)time.clock()#擷取CPU運行程式工作的時間,但sleep不算,當時CPU是不工作的time.asctime(p_tuple=‘‘)#將struk_time 格式化為字串時間如:‘Sat Jun 06 16:26:11 1998‘.time.ctime(seconds=None)#將秒數即時間戳記格式化為字串時間:‘300‘-->Thu Jan  1 08:05:00 1970time.mktime(p_tuple=‘‘)#將struc_time時間即gmtime(),localtime()格式化為時間戳記time.sleep(seconds=‘‘)#暫停多少秒

 

 

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.