python UNIX_TIMESTAMP时间处理
2013-06-27 16:23
369 查看
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)
获取按月或者小时偏移时间
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]
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)
获取按月或者小时偏移时间
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]
相关文章推荐
- python UNIX_TIMESTAMP时间处理方法分析
- python UNIX_TIMESTAMP时间处理方法分析
- PHP - strtotime time FROM_UNIXTIME UNIX_TIMESTAMP 常用的时间&时间戳处理函数
- python 时间处理
- Unix时间戳(timestamp)转换工具
- 人工智能:python 实现 第十一章,使用Pandas处理时间序列数据
- MySQL查询中时间转换--UNIX_TIMESTAMP()和from_unixtime()的使用
- python 时间处理
- Python中datetime的使用和常用时间处理
- 【python】判断时间为周末类似的处理方法
- Python3 - 时间处理与定时任务
- MySQL插入时间戳用函数:UNIX_TIMESTAMP()
- Python——处理日期和时间
- python时间,日期,时间戳处理
- Python使用arrow库优雅地处理时间数据详解
- python 时间处理
- Python时间处理
- 利用timestamp实现数据库处理同一记录的时间差异问题
- Python时间处理
- c# datetime与 timeStamp(unix时间戳) 互相转换