python 獲取utc時(shí)間轉(zhuǎn)化為本地時(shí)間的方法
方法一:
import datetime timenow = (datetime.datetime.utcnow() + datetime.timedelta(hours=8)) #將utc時(shí)間轉(zhuǎn)化為本地時(shí)間 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 字符串轉(zhuǎn)化為時(shí)間 re = dateutil.parser.parse(re_time) start_time =(st+datetime.timedelta(hours=8)) #將#將utc時(shí)間2017-12-21T04:57:42.000Z 轉(zhuǎn)化為時(shí)間本地時(shí)間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中獲取數(shù)據(jù)
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轉(zhuǎn)化UTC
utc1 = 1406869066, utc2 = 1406869070 相差4, 也就是這兩個(gè)時(shí)間相差4秒
以上這篇python 獲取utc時(shí)間轉(zhuǎn)化為本地時(shí)間的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Python獲取時(shí)間范圍內(nèi)日期列表和周列表的函數(shù)
- Python實(shí)現(xiàn)根據(jù)日期獲取當(dāng)天凌晨時(shí)間戳的方法示例
- Python基于datetime或time模塊分別獲取當(dāng)前時(shí)間戳的方法實(shí)例
- python設(shè)定并獲取socket超時(shí)時(shí)間的方法
- python簡(jiǎn)單實(shí)現(xiàn)獲取當(dāng)前時(shí)間
- python獲取當(dāng)前時(shí)間對(duì)應(yīng)unix時(shí)間戳的方法
- python獲取當(dāng)前日期和時(shí)間的方法
- python根據(jù)時(shí)間獲取周數(shù)代碼實(shí)例
相關(guān)文章
Python利用LightGBM實(shí)現(xiàn)高效的梯度提升
LightGBM是一個(gè)流行的梯度提升庫(kù),由微軟開(kāi)發(fā),并在多個(gè)機(jī)器學(xué)習(xí)競(jìng)賽中取得了優(yōu)秀的表現(xiàn),本文主要為大家介紹了如何利用LightGBM實(shí)現(xiàn)高效的梯度提升,需要的可以參考一下2023-06-06Python中的變量及簡(jiǎn)單數(shù)據(jù)類(lèi)型應(yīng)用
這篇文章主要介紹了Python中的變量及簡(jiǎn)單數(shù)據(jù)類(lèi)型應(yīng)用,簡(jiǎn)單的數(shù)據(jù)類(lèi)型包括字符串和數(shù)字,更多詳細(xì)內(nèi)容,需要的小伙伴可以參考一下2022-03-03詳解python中Numpy的屬性與創(chuàng)建矩陣
這篇文章給大家分享了關(guān)于python中Numpy的屬性與創(chuàng)建矩陣的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。2018-09-09Python中的浮點(diǎn)數(shù)原理與運(yùn)算分析
這篇文章主要介紹了Python中的浮點(diǎn)數(shù)原理與運(yùn)算分析,結(jié)合實(shí)例形式分析了Python浮點(diǎn)數(shù)操作的常見(jiàn)錯(cuò)誤,并簡(jiǎn)單解釋了浮點(diǎn)數(shù)運(yùn)算的原理與比較運(yùn)算實(shí)現(xiàn)方法,需要的朋友可以參考下2017-10-10Python類(lèi)反射機(jī)制使用實(shí)例解析
這篇文章主要介紹了Python類(lèi)反射機(jī)制使用實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12一文教會(huì)你用Python實(shí)現(xiàn)pdf轉(zhuǎn)word
python實(shí)現(xiàn)pdf轉(zhuǎn)word,支持中英文轉(zhuǎn)換,轉(zhuǎn)換精度高,可以達(dá)到使用效果,下面這篇文章主要給大家介紹了關(guān)于用Python實(shí)現(xiàn)pdf轉(zhuǎn)word的相關(guān)資料,需要的朋友可以參考下2023-01-01