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)文章
Win10里python3創(chuàng)建虛擬環(huán)境的步驟
在本篇文章里小編給大家整理的是一篇關(guān)于Win10里python3創(chuàng)建虛擬環(huán)境的步驟內(nèi)容,需要的朋友們可以學(xué)習(xí)參考下。2020-01-01
python實(shí)現(xiàn)txt文件格式轉(zhuǎn)換為arff格式
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)txt文件格式轉(zhuǎn)換為arff格式的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
python linecache讀取行更新的實(shí)現(xiàn)
本文主要介紹了python linecache讀取行更新的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
Python中的偏函數(shù)及其廣泛應(yīng)用方式
這篇文章主要介紹了Python中的偏函數(shù)及其廣泛應(yīng)用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
使用tensorflow實(shí)現(xiàn)矩陣分解方式
今天小編就為大家分享一篇使用tensorflow實(shí)現(xiàn)矩陣分解方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02
Python?Pandas?修改表格數(shù)據(jù)類型?DataFrame?列的順序案例
這篇文章主要介紹了Python?Pandas?修改表格數(shù)據(jù)類型?DataFrame?列的順序案例,文章通過主題展開詳細(xì)的相關(guān)內(nèi)容,感興趣的小伙伴可以參考一下2022-08-08

