python中的time模組

來源:互聯網
上載者:User

標籤:replace   port   時間差   struct   替換   clock   mtime   測量   包括   

#_*_coding:utf-8_*___author__ = ‘Alex Li‘import time# print(time.clock()) #返回處理器時間,3.3開始已廢棄 , 改成了time.process_time()測量處理器運算時間,不包括sleep時間,不穩定,mac上測不出來# print(time.altzone)  #返回與utc時間的時間差,以秒計算\# print(time.asctime()) #返回時間格式"Fri Aug 19 11:14:16 2016",# print(time.localtime()) #返回本地時間 的struct time對象格式# print(time.gmtime(time.time()-800000)) #返回utc時間的struc時間對象格式# print(time.asctime(time.localtime())) #返回時間格式"Fri Aug 19 11:14:16 2016",#print(time.ctime()) #返回Fri Aug 19 12:38:29 2016 格式, 同上# 日期文字 轉成  時間戳記# string_2_struct = time.strptime("2016/05/22","%Y/%m/%d") #將 日期文字 轉成 struct時間對象格式# print(string_2_struct)# ## struct_2_stamp = time.mktime(string_2_struct) #將struct時間對象轉成時間戳記# print(struct_2_stamp)#將時間戳記轉為字串格式# print(time.gmtime(time.time()-86640)) #將utc時間戳記轉換成struct_time格式# print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()) ) #將utc struct_time格式轉成指定的字串格式#時間加減import datetime# print(datetime.datetime.now()) #返回 2016-08-19 12:47:03.941925#print(datetime.date.fromtimestamp(time.time()) )  # 時間戳記直接轉成日期格式 2016-08-19# print(datetime.datetime.now() )# print(datetime.datetime.now() + datetime.timedelta(3)) #目前時間+3天# print(datetime.datetime.now() + datetime.timedelta(-3)) #目前時間-3天# print(datetime.datetime.now() + datetime.timedelta(hours=3)) #目前時間+3小時# print(datetime.datetime.now() + datetime.timedelta(minutes=30)) #目前時間+30分## c_time  = datetime.datetime.now()# print(c_time.replace(minute=3,hour=2)) #時間替換

 

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.