python UNIX_TIMESTAMP時(shí)間處理方法分析
本文實(shí)例講述了python UNIX_TIMESTAMP時(shí)間處理方法。分享給大家供大家參考,具體如下:
from datetime import datetime import time int(time.mktime(rm.start_time.timetuple())) datetime.fromtimestamp(time.time()) rf.start_time + timedelta(0, math.ceil(diff.total_seconds()/(3600*rf.period))*3600*rf.period)
獲取按月或者小時(shí)偏移時(shí)間
def getlastday(datetimeobj): year= datetimeobj.year month = datetimeobj.month + 1 if month>12: year = year + 1 month=1 return datetime(year, month, 1) - timedelta(1) def getSendTime(period, start_time): datenow = datetime.now() nextTime = preTime = start_time if period > 0 and period < 1000: diff = datetime.now() - start_time nextTime = start_time + timedelta(0, math.ceil(diff.total_seconds()/(3600*period))*3600*period) preTime = start_time + timedelta(0, math.floor(diff.total_seconds()/(3600*period))*3600*period) if period == 1001: if datenow.day>start_time.day: preTime = datetime(datenow.year, datenow.month, start_time.day) nextTime = getlastday(getlastday(datenow)+timedelta(1)) if nextTime.day > start_time.day: nextTime = datetime(nextTime.year, nextTime.month, start_time.day) else: preTime = getlastday(datetime(datenow.year, datenow.month, 1) - timedelta(1)) if preTime.day > start_time.day: preTime = datetime(preTime.year, preTime.month, start_time.day) nextTime = getlastday(datenow) if nextTime.day > start_time.day: nextTime = datetime(nextTime.year, nextTime.month, start_time.day) return preTime, nextTime
排序
reportMetaPeriodInfo.sort(lambda p1, p2:cmp(p1['k'], p2['k']))
獲取ip
import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 0)) localIP=s.getsockname()[0]
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python日期與時(shí)間操作技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
python腳本使用阿里云slb對(duì)惡意攻擊進(jìn)行封堵的實(shí)現(xiàn)
這篇文章主要介紹了python腳本使用阿里云slb對(duì)惡意攻擊進(jìn)行封堵的實(shí)現(xiàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02opencv 獲取rtsp流媒體視頻的實(shí)現(xiàn)方法
這篇文章主要介紹了opencv 獲取rtsp流媒體視頻的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08pytorch對(duì)梯度進(jìn)行可視化進(jìn)行梯度檢查教程
今天小編就為大家分享一篇pytorch對(duì)梯度進(jìn)行可視化進(jìn)行梯度檢查教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-02-02python中實(shí)現(xiàn)根據(jù)坐標(biāo)點(diǎn)位置求方位角
這篇文章主要介紹了python中實(shí)現(xiàn)根據(jù)坐標(biāo)點(diǎn)位置求方位角方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08pytorch DistributedDataParallel 多卡訓(xùn)練結(jié)果變差的解決方案
這篇文章主要介紹了pytorch DistributedDataParallel 多卡訓(xùn)練結(jié)果變差的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06