神剑山庄资源网 Design By www.hcban.com

本文实例讲述了python UNIX_TIMESTAMP时间处理方法。分享给大家供大家参考,具体如下:

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]

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python日期与时间操作技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

标签:
python,UNIX_TIMESTAMP,时间处理

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“python UNIX_TIMESTAMP时间处理方法分析”

暂无python UNIX_TIMESTAMP时间处理方法分析的评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。