Python 時間處理---------筆記

來源:互聯網
上載者:User

標籤:utc   import   ftime   str   time_t   timezone   from   rom   處理   

時區處理&格式化

import pytzfrom datetime import datetime# 設定時區timezone = pytz.timezone(‘Asia/Shanghai‘)# 格式化now_time = datetime.now(timezone).strftime("%Y-%m-%d %H:%M:%S")print(now_time)

 

直接輸出目前時間戳

import timenow_timestamps = time.time()print(now_timestamps)

datetime time 轉換

import datetimeimport timeimport pytzstr = ‘2016-10-26 23:12:19‘str2datetime = datetime.datetime.strptime(str, ‘%Y-%m-%d %H:%M:%S‘)# print(str2datetime)datetime2str = str2datetime.strftime(‘%Y-%d-%m %H:%M:%S‘)# print(datetime2str)time_tuple = str2datetime.timetuple()# print(time_tuple)time2str = time.strftime("%Y-%m-%d %H:%M:%S", time_tuple)# print(time2str)tuple2datetime = datetime.datetime(*time_tuple[0:6])# print(tuple2datetime)now_timestamps = time.time()# print(now_timestamps)time2datetime = datetime.datetime.fromtimestamp(now_timestamps)time_tuple = time.localtime(now_timestamps)print(time_tuple)#本地時區時間local = datetime.datetime.fromtimestamp(now_timestamps)print(local)#標準時區時間standard = datetime.datetime.utcfromtimestamp(now_timestamps)print(standard)#本地時區時間local_tz = time.localtime(now_timestamps)print(local_tz)#標準時區時間standard_tz = time.gmtime(now_timestamps)print(standard_tz)

 

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.