python 獲取utc時間轉(zhuǎn)化為本地時間的方法
更新時間:2018年12月31日 11:36:52 作者:sxf_0123
今天小編就為大家分享一篇python 獲取utc時間轉(zhuǎn)化為本地時間的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
方法一:
import datetime
timenow = (datetime.datetime.utcnow() + datetime.timedelta(hours=8)) #將utc時間轉(zhuǎn)化為本地時間
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)化為時間 re = dateutil.parser.parse(re_time) start_time =(st+datetime.timedelta(hours=8)) #將#將utc時間2017-12-21T04:57:42.000Z 轉(zhuǎn)化為時間本地時間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, 也就是這兩個時間相差4秒
以上這篇python 獲取utc時間轉(zhuǎn)化為本地時間的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Python利用LightGBM實現(xiàn)高效的梯度提升
LightGBM是一個流行的梯度提升庫,由微軟開發(fā),并在多個機器學習競賽中取得了優(yōu)秀的表現(xiàn),本文主要為大家介紹了如何利用LightGBM實現(xiàn)高效的梯度提升,需要的可以參考一下2023-06-06
詳解python中Numpy的屬性與創(chuàng)建矩陣
這篇文章給大家分享了關于python中Numpy的屬性與創(chuàng)建矩陣的相關知識點內(nèi)容,有興趣的朋友們可以學習參考下。2018-09-09
一文教會你用Python實現(xiàn)pdf轉(zhuǎn)word
python實現(xiàn)pdf轉(zhuǎn)word,支持中英文轉(zhuǎn)換,轉(zhuǎn)換精度高,可以達到使用效果,下面這篇文章主要給大家介紹了關于用Python實現(xiàn)pdf轉(zhuǎn)word的相關資料,需要的朋友可以參考下2023-01-01

