您好,登錄后才能下訂單哦!
這篇文章主要介紹了使用python怎么將utc時間轉化成本地時間,億速云小編覺得不錯,現在分享給大家,也給大家做個參考,一起跟隨億速云小編來看看吧!
Python是一種編程語言,內置了許多有效的工具,Python幾乎無所不能,該語言通俗易懂、容易入門、功能強大,在許多領域中都有廣泛的應用,例如最熱門的大數據分析,人工智能,Web開發(fā)等。
方法一:
import datetime timenow = (datetime.datetime.utcnow() + datetime.timedelta(hours=8)) #將utc時間轉化為本地時間 timetext = timenow.strftime('%y%m%d')
方法二:
import datetime import dateutil.parser st_time = hit['_source']['start_time'] re_time = hit['_source']['report_time'] igmp_delay = hit['_source']['igmp_delay'] live_delay = hit['_source']['live_delay'] st = dateutil.parser.parse(st_time) #將2017-12-21T04:57:42.000Z 字符串轉化為時間 re = dateutil.parser.parse(re_time) start_time =(st+datetime.timedelta(hours=8)) #將#將utc時間2017-12-21T04:57:42.000Z 轉化為時間本地時間2017-12-21 12:57:42+00:00 report_time = (re+datetime.timedelta(hours=8)) message = str(start_time)[0:19]+","+str(report_time)[0:19]+","+str(int(igmp_delay))+","+str(int(live_delay))+"\n"
python 從es中獲取數據
import os import datetime from elasticsearch import Elasticsearch import dateutil.parser es = Elasticsearch(hosts="127.0.0.1",timeout=10000) write_file=open('C:\\Users\\Administrator\\Desktop\\gather-005-201712210.csv',"a+",encoding="utf-8") rs = es.search( index = "gather-005-20171221", body={ "size":42, "query": { "term": { "itv_account": { "value": "38:FA:CA:D9:5F:2B" } } }, "sort": [ { "report_time": { "order": "desc" } } ], "_source": ["start_time","report_time","igmp_delay","live_delay"] } ) for hit in rs['hits']['hits']: st_time = hit['_source']['start_time'] re_time = hit['_source']['report_time'] igmp_delay = hit['_source']['igmp_delay'] live_delay = hit['_source']['live_delay'] st = dateutil.parser.parse(st_time) re = dateutil.parser.parse(re_time) start_time =(st+datetime.timedelta(hours=8)) report_time = (re+datetime.timedelta(hours=8)) message = str(start_time)[0:19]+","+str(report_time)[0:19]+","+str(int(igmp_delay))+","+str(int(live_delay))+"\n" write_file.write(message) write_file.close()
方法三:
UTC轉化UTC
utc1 = 1406869066, utc2 = 1406869070 相差4, 也就是這兩個時間相差4秒
以上就是億速云小編為大家收集整理的使用python怎么將utc時間轉化成本地時間,如何覺得億速云網站的內容還不錯,歡迎將億速云網站推薦給身邊好友。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。